Intermediate · 7 min · practise every command in the built-in terminal

chown — Change File Owner

chown changes who owns a file.

Syntax

chown user file
chown user:group file
chown :group file          # Change only group

Examples

chown student myfile.txt
chown student:student myfile.txt
chown -R student:student directory/

Who can use chown?

Only root can change file ownership. Regular users can only change group to one they belong to.

sudo chown root:root sensitive.txt
sudo chown -R www-data:www-data /var/www/html

chgrp — Change group only

chgrp developers project/
chgrp -R www-data /var/www/

Check ownership

ls -la file.txt
stat file.txt          # Detailed file info

Real-world example

When you upload files to a web server:

sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/

Practice tasks

  1. Check the owner of files in your home directory
  2. Use stat to see detailed info about README.txt
  3. Create a file and change its owner to student
  4. Change both the owner and group of a file at once

Commands in this lesson

Permissions