Changing ownership (chown) and permissions (chmod)
You’ll use two commands to change ownership and permissions on files: chown
and chmod
.
Chown
chown
(change owner) is used to change the owner and group of a file. It’s used in the following way:
chown [OPTION]... [OWNER][:[GROUP]] FILE...
For example, imagine we have this file:
$ ls -lh testfile
-rw-r--r-- 1 dave dave 10 Aug 14 16:18 testfile
Change owner
Let’s change the owner to chris
(presuming there’s a chris
user on the system):
$ chown chris testfile
$ ls -lh testfile
-rw-r--r-- 1 chris dave 10 Aug 14 16:18 testfile
Change owner and group
We’ve changed the owner, but if we wanted to change the group, too, we could have run:
$ chown chris:staff testfile
$ ls -lh testfile
-rw-r--r-- 1 chris staff 10 Aug 14 16:18 testfile
Recursively change owner and group
One common task is changing the owner and group for all files in a given directory...