File Operations: chown - Change File Owner

Every file/directory in an Operating System like Linux or macOS (and every UNIX systems in general) has an owner.

The owner of a file can do everything with it. It can decide the fate of that file.

The owner (and the root user) can change the owner to another user, too, using the chown command:

chown <owner> <file>

Like this:

chown flavio test.txt

For example if you have a file that’s owned by root, you can’t write to it as another user:

You can use chown to transfer the ownership to you:

It’s rather common to have the need to change the ownership of a directory, and recursively all the files contained, plus all the subdirectories and the files contained in them, too.

You can do so using the -R flag:

chown -R <owner> <file>

Files/directories don’t just have an owner, they also have a group. Through this command you can change that simultaneously while you change the owner:

chown <owner>:<group> <file>

Example:

chown flavio:users test.txt

You can also just change the group of a file using the chgrp command:

chgrp <group> <filename>

The chown command works on Linux, macOS, WSL, and anywhere you have a UNIX environment

Lessons in this unit:

0: Introduction
1: mkdir - Make Directory
2: rmdir - Remove Directory
3: touch - Create/Update Files
4: cp - Copy Files
5: mv - Move/Rename Files
6: open - Open Files
7: ln - Create Links
8: chmod - Change File Permissions
9: ▶︎ chown - Change File Owner
10: umask - Set Default Permissions

Join my AI Workshop!

The Web Development BOOTCAMP cohort starts in February 2026