Ubuntu – the main difference between chmod and chown

chmodchowncommand linepermissionsusers

In some examples, I saw that some used chown instead of chmod. I do not know where to use chmod and chown. Please explain to me the difference between them, when and why I should use either.

Best Answer

Let's create a file

touch rainbow

Let's have a look at the file's metadata

$ ls -l rainbow
-rw-rw-r-- 1 zanna zanna 0 May 24 10:09 rainbow

The first part of the information is the file type (- at the beginning means it's a regular file) and the permission bits

After that we see the owner (zanna) and the group (zanna). We can use the chown command to change those:

$ sudo chown pixie rainbow
$ ls -l rainbow
-rw-rw-r-- 1 pixie zanna 0 May 24 10:09 rainbow

And we use chmod to change the permission bits

$ sudo chmod 333 rainbow
$ ls -l rainbow
--wx-wx-wx 1 pixie zanna 0 May 24 10:09 rainbow

Since the permission bits are set separately for owner, group and others, you can control file permissions for different users by combining chown and chmod. See this short guide for a crash course on permissions in Linux.