Linux Commands | File Management | chown Change File/Directory Ownership
Check Ownership
To check ownership, use the following command.
ls -al
The command prints output in the following format.
-rw-r--r-- 1 kimkc staff 36864 5 10 2015 Currency.db
Here, the owner is kimkc, and the group identifier is staff.
Change File Ownership
Run the following command with root privileges.
Command
chown {owner}:{group identifier} {file name whose ownership you want to change}
The following command changes the owner of test.sh to aaa and the group identifier to bbb.
Example
chown aaa:bbb test.sh
Change Directory Ownership
Run the following command with root privileges.
Command
chown {owner}:{group identifier} {directory name whose ownership you want to change}
The following command changes only the owner of the /home/test directory to aaa and the group identifier to bbb.
Example
chown aaa:bbb /home/test
With this command, only the ownership of the /home/test directory changes. Subdirectories below it are not changed.
Change Ownership Including Subdirectories
Run the following command with root privileges.
Command
chown -R {owner}:{group identifier} {directory name whose ownership you want to change}
The following command changes the owner of the /home/test directory and all subdirectories and files under it to aaa, and changes the group identifier to bbb.
Example
chown -R aaa:bbb /home/test
With this command, the ownership of /home/test and all directories below it is changed.