chmod Command Examples in Linux

The chmod command enables you to modify the permissions of a file or directory. Only the owner of the file or directory or the system administrator can change the permissions of the object.


The syntax of the chmod command is:

# chmod [options] {mode} {file/directory name}

chmod Command Options

The chmod command supports different options to modify permissions. One or more of these options may be used at a time.

Option Used To
-c Report changes made to permissions.
-f Hide most error messages.
-v Display diagnostic entry for every object processed.
-R Modify permissions recursively.

chmod Command Examples

1. To change the file permissions:

# chmod r+x,g-x,o=r-- file.txt

2. To change the file permissions using the octal values:

# chmod 777 file.txt

3. To see if the changes have been taken affect or not after firing the command:

# chmod -c 777 file.txt

4. To apply the changes recursively:

# chmod -R 777 /mydir/

5. To set the verbose mode:

# chmod -v 777 /mydir/

6. To change the MODE of each file to preserve root:

# chmod --preserve-root FILE

7. To change the MODE of each file not to preserve root:

# chmod --no-preserve-root FILE

8. To set MODE from reference file:

# chmod --reference=RFILE FILE

9. To see the help for chmod:

# chmod --help

10. To see the version for the chmod:

# chmod --verbose