To change directory permissions in Linux, use the following commands:
- chmod +rwx filename to add read, write and execute.
- chmod +x filename to accept executable permissions.
- chmod -rwx directory name to remove read, write and execute.
- chmod -wx filename to remove write and executable permissions.
The letters: r stands for read, w for write and x is for executing.
These permissions apply only for the owner of the file.
In the above screengrab, you can see the list of a directory. Each file and each folder have permissions, which are the four sections explained below.
|“-” indicates a file|
“d” is a direcory
“l” symbolic link
|Read, Write |
|Read, Write |
|Read, Write |
Changing Directory Permissions in Linux for the Group Owners and Others
For group owners, commands for changing directory permissions are almost similar but you add ‘g’ for the group and ‘o’ for other users. The commands are:
chmod g+w filename – For Group, add write
chmod g-wx filename – For Group revoke write and execute
chmod o+w filename – For Owner, add write
chmod o-rwx folder name – For Owner, revoke all
In directory permissions Linux: “u” stands for users, “g” for the group, “o” for others, and “ugo” or “a” (for all).
chmod ugo+rwx [folder name] to give Read, write, and execute permission to everyone.
chmod a=r [folder name] to provide read permissions for everyone.
Changing Groups of Files and Directories in Linux
Use these commands to change groups of files and directories in Linux.
chgrp group-name filename
chgrp group-name [folder name]
The group must exist before one can assign files and directories to it.
Changing Ownership in Linux
To change ownership of files and directories in Linux, use the following commands:
chown name filename
chown name folder name
These commands give ownership to someone else, but all sub files and directories belong to the original owner still.
There is also a command to combine a group and ownership.
chown -R name:filename /home/name/directory name
This command will give someone ownership of the directory you supply, and all files and subfolders. The -R stands for recursive, which transfers ownership of all subdirectories to a new owner.
Changing Permissions in Numeric Code in Linux
In this case, you use numbers instead of using “r”, “w”, or “x”.
- 0 means No Permission
- 1 means Execute
- 2 means Write
- 4 means Read
Add the numbers up when giving a particular level of directory permissions in Linux.
[root@dev paul]# ls -l total 4 -rw-rw-rw- 1 peter paul 0 May 10 12:40 test-file.txt drwxrwx--- 2 peter paul 4096 May 10 12:40 test-folder [root@dev paul]# chmod 777 test-file.txt [root@dev paul]# chmod 421 test-folder/ [root@dev paul]# ls -l total 4 -rwxrwxrwx 1 peter paul 0 May 10 12:40 test-file.txt dr---w---x 2 peter paul 4096 May 10 12:40 test-folder [root@dev paul]# chmod 124 test-file.txt [root@dev paul]# ls -l total 4 ---x-w-r-- 1 peter paul 0 May 10 12:40 test-file.txt dr---w---x 2 peter paul 4096 May 10 12:40 test-folder [root@dev paul]#
Permission in numbers are:
- 0 = —
- 1 = –x
- 2 = -w-
- 3 = -wx
- 4 = r-
- 5 = r-x
- 6 = rw-
- 7 = rwx
- chmod 777 folder name will give read, write, and execute permissions for everyone.
- chmod 700 folder name will give read, write, and execute permissions for the user only.
- chmod 327 folder name will give write and execute (3) permission to the user, w (2) for the group, and then read, write, and execute for other users.