How to change group of a file on Linux?
January 2023 • 121 words • 1 min read
On Linux and other Unix like systems, if you want to check the user who owns a file, you can use ls -l
comand:
# /tmp/test1 is the name of the file
$ ls -l /tmp/test1
-rw-r--r-- 1 abhinav staff 1369 Jan 29 10:28 /tmp/test1
Change file owner using chown
If you want to change the owner of the file to say a user named deploy
, do the following:
# /tmp/test1 is the name of the file
$ chown deploy /tmp/test1
$ ls -l /tmp/test1
-rw-r--r-- 1 deploy staff 1369 Jan 29 10:28 /tmp/test1
Change the group of the file using chgrp
If you want to change the group the file belongs to, you can do the following:
# /tmp/test1 is the name of the file
$ chgrp deploy /tmp/test1
$ ls -l /tmp/test1
-rw-r--r-- 1 deploy deploy 1369 Jan 29 10:28 /tmp/test1
BTW, there’s another shortcut. You can use chown
command to change the group too.
# /tmp/test1 is the name of the file
$ chown deploy:deploy /tmp/test1
$ ls -l /tmp/test1
-rw-r--r-- 1 deploy staff 1369 Jan 29 10:28 /tmp/test1
There’s another helpful command chmod
that can you manage read, write and execute permissions at a much granular level. I will write more on chmod
in a later post. Meanwhile, you can read more about chown
, chgrp
and chmod
by using man
command.
$ man chmod