217 views

What is the use of the chmod command in Linux?

In Linux (CentOS/Ubuntu/Alpine etc) operating systems, the chmod command is used to change the permission of file(s) or folder(s) access permissions.

Illustrating how the numbers are formed

  • Above Example, there are USER, GROUP, and OTHERS
  • Weight for READ(r) is 4
  • Weight for WRITE(w) is 2
  • Weight for EXECUTE(x) is 1
  • We need to give ALL permissions to USER
  • That is, READ(r), WRITE(w) and EXECUTE(x)
  • Summing up the weight for each segments similar way, we get 7, 6 and 0
  • Issuing chmod 760 would give us the required result.
  • USER will have all permissions
  • GROUP will have read and write (no execution)
  • OTHERS will have no permission to READ/WRITE/EXECUTE

A list of example files list with different permissions:

-r-------- 1 developer developer  0 Mar  1 04:34 file1.txt
-r--r----- 1 developer developer  0 Mar  1 04:34 file2.txt
-r--r--r-- 1 developer developer  0 Mar  1 04:34 file3.txt
-rw-rw-rw- 1 developer developer  0 Mar  1 04:34 file4.txt
-rwxrw-rw- 1 developer developer  0 Mar  1 04:34 file5.txt
-rwxrwxrw- 1 developer developer  0 Mar  1 04:34 file6.txt
-rwxrwxrwx 1 developer developer  0 Mar  1 04:34 file7.txt
---x------ 1 developer developer  0 Mar  1 04:34 file8.txt
-rwx------ 1 developer developer  0 Mar  1 04:34 file9.txt

Try to practice chmod with the magic number for each of these files given above and verify you get the expected results.

A few practical chmod examples

References:

https://en.wikipedia.org/wiki/Chmod

Oct 21, 2010 by | 217 views
DevOpsRun.com is LIVE!

Articles for DevOps Geeks
MobaXterm Customization
CHMOD Explained!
Bash history powerful tips
Ubuntu bash from Windows
..