How to use the chmod command in Linux


The chmod command sets the file permissions flags on a file or folder. The flags define who can read, write to or execute the file. When you list files with the -l (long format) option you’ll see a string of characters that look like

Add write permission (w) to the Group's (g) access modes of a directory
chmod g+w dirname
ls -l
-rw-r--r-- 12 root root
|[-][-][-]-  [--] [--]
| |  |  | |   |    |
| |  |  | |   |    +--> 7. Group
| |  |  | |   +-------> 6. Owner
| |  |  | +-----------> 5. Alternate Access Method
| |  |  +-------------> 4. Others Permissions
| |  +----------------> 3. Group Permissions
| +-------------------> 2. Owner Permissions
+---------------------> 1. File Type

How to change directory permissions in Linux

add permissions
chmod +rwx filename
remove permissions
chmod -rwx
cat: Permission denied

To change directory permissions for everyone, use “u” for users, “g” for group, “o” for others, and “ugo” or “a” (for all).

give read, write, and execute to everyone
chmod ugo+rwx foldername
chmod u=rw,og=r
include files in subdirectories
chmod -R o-r *.page

The syntax for the chmod command is as follows:

  chmod [OPTION]... MODE[,MODE]... FILE...
  chmod [OPTION]... OCTAL-MODE FILE...
  chmod [OPTION]... --reference=RFILE FILE...

change the mode of each FILE to that of RFILE.
-c, --changes
like verbose but report only when a change is made
-f, --silent, --quiet
suppress most error messages
-v, --verbose
output a diagnostic for every file processed
do not treat '/' specially (the default)
fail to operate recursively on '/'
use RFILE's mode instead of MODE values
-R, --recursive
change files and directories recursively
display this help and exit
output version information and exit
The file owner.
The users who are members of the group.
All other users.
All users, identical to ugo.

Related Tags

#Linux# #chmod#