chmod Command in Linux

Change a file's permissions from the Linux command line

Man using computer
Comstock Images/Stockbyte/Getty Images

The chmod command lets you change the access permissions of files and folders. 

The chmod command, like other commands, can be executed from the command line or through a script file.

If you need to list a file's permissions, use the ls command.

chmod Command Syntax

This is the proper syntax when using the chmod command:

chmod [options] mode[,mode] file1 [file2 ...]

The following are some of the usual options used with chmod:

  • -f, --silent, --quiet (suppresses most error messages)
  • -v, --verbose (outputs a diagnostic for every file processed)
  • -c, --changes (like verbose but reports only when a change is made)
  • -R, --recursive (change files and directories recursively)
  • --help (displays help and exits)
  • --version (outputs version information and exits)

Below is a list of several numerical permissions that can be set for the user, group, and everyone else on the computer. Next to the number is the read/write/execute letter equivalent.

  • 7, rwx, read, write, and execute
  • 6, rw-, read and write
  • 5, r-x, read and execute
  • 4, r--, read only
  • 3, -wx, write and execute
  • 2, -w-, write only
  • 1, --x, execute only
  • 0, ---, none

chmod Command Examples

If you, for example, wanted to change the permissions of the file "participants" so that everybody has full access to it, you would enter:

chmod 777 participants

The first 7 sets the permissions for the user, the second 7 sets the permissions for the group, and the third 7 sets the permissions for everybody else.

If you want to be the only one who can access it, you would use:

chmod 700 participants

To give yourself and your group members full access:

chmod 770 participants

If you want to keep full access for yourself, but want to keep other people from modifying the file, you can use:

chmod 755 participants

The following uses the letters from above to change the permissions of "participants" so that the owner can read and write to the file, but it doesn't change permissions for anyone else:

chmod u=rw participants

More Information on the chmod Command

You can change the group ownership of existing files and folders with the chgrp command. Change the default group for new files and folders with the newgrp command.

Remember that symbolic links used in a chmod command will affect the true, target object.

Setting Modes

Use chmod to set additional file-system modes for files and directories. For example, to set the sticky bit — which means that only the file owner, the directory owner or the root superuser can delete the file, regardless of the file's read-and-write group permissions — prefix a 1 to the number sequence:

chmod 1755 participants