How to change file Ownership

Changing File Ownership

  • Only root can change a file’s owner
  • Only root or the owner can change a file’s group
  • Ownership is changed with chown:
    • chown {-R} user_name file|directory...
  • Group-Ownership is changed with chgrp:
    • chgrp [-R] group_name file|directory...

File ownership can be changed with the chown command. For example, to grant ownership of the file “test.txt” to amar, the following command could be used:

amar@amar-pc:~/Desktop$ sudo chown amar test.txt
How to change file Ownership

chown can be used with the -R option to recursively change the ownership of an entire directory tree. The following command would grant ownership of testdir and all files and subdirectories within it to student:

amar@amar-pc:~/Desktop$ sudo chown -R amar testdir/
How to change file Ownership

Only root can change the ownership of a file. Group ownership, however, can be set by root or the file’s owner. root can grant ownership to any group, while non-root users can grant ownership only to groups they belong to. Changing the group ownership of a file is done with the chgrp command. The syntax is identical to that of chown, including the use of -R to affect entire directory trees.

1 thought on “How to change file Ownership”

Leave a Comment

%d bloggers like this: