Skip to content

Linux commands: chown

New Course Coming Soon:

Get Really Good at Git

A quick guide to the `chown` command, used to change the owner of a file

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>


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

Are you intimidated by Git? Can’t figure out merge vs rebase? Are you afraid of screwing up something any time you have to do something in Git? Do you rely on ChatGPT or random people’s answer on StackOverflow to fix your problems? Your coworkers are tired of explaining Git to you all the time? Git is something we all need to use, but few of us really master it. I created this course to improve your Git (and GitHub) knowledge at a radical level. A course that helps you feel less frustrated with Git. Launching May 21, 2024. Join the waiting list!

Here is how can I help you: