Changes the permission of a file.
chmod [OPTION]... MODE[,MODE]... FILE...
chmod [OPTION]... OCTAL-MODE FILE...
chmod [OPTION]... --reference=RFILE FILE...
|-c, –changes||like verbose but report only when a change is made|
|–no-preserve-root||do not treat `/’ specially (the default)|
|–preserve-root||fail to operate recursively on `/’|
|-f, –silent, –quiet||suppress most error messages|
|-v, verbose||output a diagnostic for every file processed|
|–reference=RFILE||use RFILE’s mode instead of MODE values|
|-R, –recursive||change files and directories recursively|
|–help||display this help and exit|
|–version||output version information and exit|
u - User who owns the file.
g - Group that owns the file.
o - Other.
a - All.
r - Read the file.
w - Write or edit the file.
x - Execute or run the file as a program.
CHMOD can also to attributed by using Numeric Permissions:
400 read by owner
040 read by group
004 read by anybody (other)
200 write by owner
020 write by group
002 write by anybody
100 execute by owner
010 execute by group
001 execute by anybody
The above numeric permissions can be added to set a certain permission, for example, a common HTML file on a Unix server to be only viewed over the Internet would be:
chmod 644 test.html
This gives the file read/write by the owner and only read by everyone else
Files such as scripts that need to be executed need more permissions. Below is another example of a common permission given to scripts.
chmod 755 test.cgi
This would be the following 400+040+004+200+100+010+001 = 755 where you are giving all the rights except the capability for anyone to write to the file.cgi file(-rwxr-xr-x).
chmod 666 test.txt
Finally, another common CHMOD permission is 666, as shown below, which is read and write by everyone.
Below is an example of how a file may be listed when typing ( ls -l ) at the prompt as well as information on how to interpret it.
-rw-rw-r– 1 swapnil 123 Nov 14 15:36 test.txt
|–||rw||rw-||r–||1||swapnil||123||Nov 14 15:36||test.txt|
|File||owner||group||everyone else||links||owner||size||mod date||file name|
Hope you find this tutorial helpful. Feel free to ask questions! Don’t forget to like or to leave a comment if its really help you.