Chmod Examples

chmod 754

$ chmod 754 foo.sh
$ chmod u=rwx,g=rx,o=r foo.sh

Executable

$ chmod +x ~/example.py
$ chmod u+x ~/example.py
$ chmod a+x ~/example.py

Removing Permissions

In order to remove read write permissions given to a file, use the following syntax:

$ chmod o-rw example.txt

For our file example.txt, we can remove read write permissions using chmod for group by running the following command:

$ chmod g-rx example.txt

To remove chmod read write permissions from the group while adding read write permission to public/others, we can use the following command:

$ chmod g-rx, o+rx example.txt

But, if you wish to remove all permissions for group and others, you can do so using the go= instead:

$ chmod go= example.txt

Symbolic mode

Deny execute permission to everyone.

$ chmod a-x chmodExampleFile.txt

Allow read permission to everyone.

$ chmod a+r chmodExampleFile.txt

Make a file readable and writable by the group and others.

$ chmod go+rw chmodExampleFile.txt

Make a shell script executable by the user/owner.

$ chmod u+x chmodExampleScript.sh

Allow everyone to read, write, and execute the file and turn on the set group-ID.

$ chmod =rwx,g+s chmodExampleScript.sh

chmod 777

$ chmod 777 example.txt
$ chmod u=rwx,g=rwx,o=rwx example.txt
$ chmod a=rwx example.txt

chmod 664

$ chmod 664 example.txt
$ chmod u=rw,g=rw,o=r example.txt
$ chmod a+rwx,u-x,g-x,o-wx example.txt

chmod 600

$ chmod 600 example.txt
$ chmod u=rw,g=,o= example.txt
$ chmod a+rwx,u-x,g-rwx,o-rwx example.txt

Operators

Symbol Description
+ Add
- Remove
= Set
Comments