Search

How to use chmod command to change Linux file permissions

The Linux chmod command can be used to change the existing permissions on a file.

The below character references are used with chmod command to identify the Linux users/Linux groups/world (other Linux users) to whom the new permissions apply. If no references are specified it defaults to “all”.

 Reference

Description

u

user - the owner of the file

g

group -         users who are members of the file's group

o

others (world) - users who are not the owner of the file or members of the group

a

all - all three of the above, is the same as ugo

The Linux chmod command uses an operator to specify how the file permissions should be changed. The following table lists the chmod command operators.

Operator

Description

+

adds the specified modes to the specified classes

-

removes the specified modes from the specified classes

=

Used to assign permission of one type of account to another

 

Example 1 (user is given execute permission using chmod command):

[[email protected] chmodtest]# ls -l
total 0
-rw-r--r-- 1 root root 0 Jul  4 17:52 chmodtest
[[email protected] chmodtest]# chmod u+x chmodtest
[[email protected] chmodtest]# ls -l
total 0
-rwxr--r-- 1 root root 0 Jul  4 17:52 chmodtest

 

Example 2 (the permission of user is assigned to group using chmod command):

[[email protected] chmodtest]# ls -l
total 0
-rwxr--r-- 1 root root 0 Jul  4 17:52 chmodtest
[[email protected] chmodtest]# chmod g=u chmodtest
[[email protected] chmodtest]# ls -l
total 0
-rwxrwxr-- 1 root root 0 Jul  4 17:52 chmodtest

 

Example 3 (the permissions of group and world are removed using chmod command):

[[email protected] chmodtest]# ls -l
total 0
-rwxrwxr-- 1 root root 0 Jul  4 17:52 chmodtest
[[email protected] chmodtest]# chmod go= chmodtest
[[email protected] chmodtest]# ls -l
total 0
-rwx------ 1 root root 0 Jul  4 17:52 chmodtest
[[email protected] chmodtest]#

Example 4 (execute permission is removed from all using chmod command)

[[email protected] chmodtest]# ls -l
total 0
-rwx------ 1 root root 0 Jul  4 17:52 chmodtest
[[email protected] chmodtest]# chmod -x chmodtest
[[email protected] chmodtest]# ls -l
total 0
-rw------- 1 root root 0 Jul  4 17:52 chmodtest
[[email protected] chmodtest]#

The Linux chmod command also supports octal notation. Following table lists the octal values which can be used with chmod command.

 Octal Value

Permission

4

Read permission (r)

2

Write permission (w)

1

Execute Permission (x)

The following table lists the summary of permissions denoted by octal values.

Octal Value

Permission

Summary

0

---

No permission

1

--x

Execute

2

-w-

Write

3

-wx

Write and Execute

4

r--

Read

5

r-x

Read and Execute

6

rw-

Read and Write

7

rwx

Read, Write and Execute

The following example sets read, write and execute permissions for user, group and world.

[[email protected] chmodtest]# chmod 777 chmodtest
[[email protected] chmodtest]# ls -l
total 0
-rwxrwxrwx 1 root root 0 Jul  4 17:52 chmodtest

Related Tutorials
• The Linux File Permissions
• How to use chgrp command to change Linux group ownership of a file
• How to use chown command to change linux user ownership of a file
• Linux setuid and setgid
• What is Linux umask?