41

How can I use the chown command to change the ownership of all a folder's subfolders and files?

  • 1
    chown -R should work for you. – Wayne_Yux Nov 3 '15 at 12:59
  • 2
    chown -R your_username:your_group folder – Alex Lowe Nov 3 '15 at 13:15
52

From chown --help:

Usage: chown [OPTION]... [OWNER][:[GROUP]] FILE...
  or:  chown [OPTION]... --reference=RFILE FILE...
Change the owner and/or group of each FILE to OWNER and/or GROUP.

[...]

  -R, --recursive        operate on files and directories recursively

[...]

So you need to run (probably with sudo):

chown -R USERNAME:GROUPNAME /PATH/TO/FILE

Or, if the group shall be the specified user's primary group (usually same name), you can also omit the GROUPNAME and just give the USERNAME: with a colon (no space before it!). It will be set implicitly:

chown -R USERNAME: /PATH/TO/FILE

To only change the user and leave the group as it is, just specify USERNAME and no group name and no colon:

chown -R USERNAME /PATH/TO/FILE

To only change the group and leave the owner user as it is, just specify :GROUPNAME with a leading colon:

chown -R :GROUPNAME /PATH/TO/FILE
9

My username is timo and I did this to take ownership to all my files and folders on home directory (transferred from another account):

~$ sudo chown -R timo /home/timo/*
7
chown -R <username>:<groupname> <folder>

This is how I normally do it, and I usually do this one folder at a time. Doesn't take but a few moments to work through each folder.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.