chown and chgrp in Linux
Change ownership of file with chown
chown can change ownership of file or directories. We can use chown as well as chmod to change ownership file only difference is with chown group ownership can’t be changed. To change group ownership we use chgrp command. chown and chgrp can change user and group ownership respectively.
Syntax chown
chown user filename
chown user directoryname
This command recursively changes ownership of complete directory
chown -R user directoryname
[adsenseyu1]
Example change ownership of a file with chown
- Only root can change user permission of file To provide test, user access to file new, use command.
chown new test
Example change ownership of a directory with chown
- To change ownership of directory test to user manager use
chown manager test
- To change ownership of all content of directory test to user manager use
chown -R manager test
Change group ownership of file use command chgrp
chgrp can change ownership of file or directories. chgrp can be used by root and file owner change group ownership. Root can grant group access to any file while user can grant group access to group they are member of.
Syntax chgrp
chgrp group filename
chgrp group directoryname
Recursively change ownership of complete directory
chgrp -R user directoryname
Example change group ownership of a file with chgrp
- To provide test, group access to file new, use command.
chgrp new test
Example change group ownership of a directory with chgrp
- To change ownership of directory test to group manager use.
chgrp manager test
- To change ownership of all content of directory test to user manager use
chgrp -R manager test
In this guide we have covered basic use of command chown and chgrp in Linux.