Chmod Command
Chmod Command
The chmod command sets the file permissions flags on a file or folder. The flags
define who can read, write to or execute the file. When you list files with the -l
(long format) option you’ll see a string of characters that look like
-rwxrwxrwx
One way to use chmod is to provide the permissions you wish to give to the owner,
group, and others as a 3 digit number. The leftmost digit represents the owner.
The middle digit represents the group. The rightmost digit represents the others.
The digits you can use and what they represent are listed here:
0: No permission
1: Execute permission
2: Write permission
3: Write and execute permissions
4: Read permission
5: Read and execute permissions
6: Read and write permissions
7: Read, write and execute permissions
Looking at our example.txt file, we can see that all three sets of characters are
rwx. That means everyone has read, write and execute rights with the file.
To set the permission to be read, write, and execute (7 from our list) for the
owner; read and write (6 from our list) for the group; and read and execute (5 from
our list) for the others we’d need to use the digits 765 with the chmod command:
To set the permission to be read, write and execute (7 from our list) for the
owner, and read and write (6 from our list) for the group and for the others we’d
need to use the digits 766 with the chmod command: