chmod - Unix, Linux Command
chmod - To change access permissions, change mode.
chmod [Options]... Mode [,Mode]... file... chmod [Options]... Numeric_Mode file... chmod [Options]... --reference=RFile file...
chmod changes the permissions of each given file according to mode, where mode describes the permissions to modify. Mode can be specified with octal numbers or with letters.
|-f, --silent, --quiet||suppress most error messages|
|-v, --verbose||output a diagnostic for every file processed|
|-c, --changes||like verbose but report only when a change is made|
|-c, --reference=RFile||use RFile's mode instead of MODE values|
|-R, --recursive||change files and directories recursively|
|--help||display help and exit|
|--version||output version information and exit|
The format of a numberic mode is 'augo'
A numeric mode is from one to four octal digits (0-7), derived by adding up the bits with values 4, 2, and 1. Any omitted digits are assumed to be leading zeros. The first digit selects the set user ID (4) and set group ID (2) and sticky (1) attributes. The second digit selects permissions for the user who owns the file: read (4), write (2), and execute (1); the third selects permissions for other users in the file's group, with the same values; and the fourth for other users not in the file's group, with the same values.
Read by owner only
$ chmod 400 sample.txt
Read by group only
$ chmod 040 sample.txt
Read by anyone
$ chmod 004 sample.txt
Write by owner only
$ chmod 200 sample.txt
Write by group only
$ chmod 020 sample.txt
Write by anyone
$ chmod 002 sample.txt
Execute by owner only
$ chmod 100 sample.txt
Execute by group only
$ chmod 010 sample.txt
Execute by anyone
$ chmod 001 sample.txt
Allow read permission to owner and group and anyone.
$ chmod 444 sample.txt
Allow everyone to read, write, and execute file.
$ chmod 777 sample.txt
The format of a symbolic mode is '[ugoa...][[+-=][rwxXstugo...]...][,...]'. Multiple symbolic operations can be given, separated by commas. A combination of the letters 'ugoa' controls which users' access to the file will be changed: the user who owns it (u), other users in the file's group (g), other users not in the file's group (o), or all users (a). If none of these are given, the effect is as if 'a' were given, but bits that are set in the umask are not affected.
The operator '+' causes the permissions selected to be added to the existing permissions of each file; '-' causes them to be removed; and '=' causes them to be the only permissions that the file has.
The letters 'rwxXstugo' select the new permissions for the affected users: read (r), write (w), execute (or access for directories) (x), execute only if the file is a directory or already has execute permission for some user (X), set user or group ID on execution (s), sticky (t), the permissions granted to the user who owns the file (u), the permissions granted to other users who are members of the file's group (g), and the permissions granted to users that are in neither of the two preceding categories (o).
Deny execute permission to everyone.
$ chmod a-x sample.txt
Allow read permission to everyone.
$ chmod a+r sample.txt
Make a file readable and writable by the group and others.
$ chmod go+rw sample.txt
Make a shell script executable by the user/owner.
$ chmod u+x samplescript.sh
Allow everyone to read, write, and execute the file and turn on the set group-ID.
$ chmod =rwx,g+s samplescript.sh