Back to: Linux
Linux file permissions are used to control who can access, modify, and execute files and directories in a Linux system. Here is a cheat sheet to help you understand and manage Linux file permissions:
Types of Access
There are three types of access in Linux file permissions:
Type of Access | Symbol | Description |
---|---|---|
Read | r | Allows the user to view the contents of a file or directory. |
Write | w | Allows the user to modify the contents of a file or directory. |
Execute | x | Allows the user to execute a file or access the contents of a directory. |
File Permission Notation
Linux file permissions are represented in a 10-character string of letters and symbols. Here’s how to read it:
Character | Meaning |
---|---|
1st | File type and any special permissions |
2-4 | Owner permissions |
5-7 | Group permissions |
8-10 | Others permissions |
The first character in the string represents the file type and any special permissions. The remaining nine characters represent the owner, group, and others’ permissions, in sets of three.
Numeric Permission Notation
Numeric permission notation is another way to represent Linux file permissions. Here’s how to read it:
Permission | Numeric | Symbolic |
---|---|---|
No permissions | 0 | — |
Execute | 1 | x |
Write | 2 | w |
Write and execute | 3 | wx |
Read | 4 | r |
Read and execute | 5 | rx |
Read and write | 6 | rw |
Read, write, and execute | 7 | rwx |
Each permission set is assigned a number, from 0 to 7, based on the binary representation of the permission bits. For example, a permission string of “rw-r–r–” would be represented in numeric notation as “644.”
Managing File Permissions
Here are some commands to manage file permissions in Linux:
Command | Description |
---|---|
chmod | Change the permissions of a file or directory. |
chown | Change the owner of a file or directory. |
chgrp | Change the group of a file or directory. |
Examples
To change the permissions of a file named example.txt
to read and write for the owner and read-only for everyone else:
chmod 644 example.txt
To change the owner of a file named example.txt
to newowner
:
chown newowner example.txt
To change the group of a file named example.txt
to newgroup
:
chgrp newgroup example.txt
Octal Table:
Here is a table that explains the octal, binary, and symbolic values used in Linux file permissions:
Octal | Binary | Symbolic | Permission Type |
---|---|---|---|
0 | 000 | — | No permissions |
1 | 001 | –x | Execute |
2 | 010 | -w- | Write |
3 | 011 | -wx | Write/execute |
4 | 100 | r– | Read |
5 | 101 | r-x | Read/execute |
6 | 110 | rw- | Read/write |
7 | 111 | rwx | Read/write/execute |
Also, see the example code shell-scripting-examples in our GitHub repository. See complete examples in our GitHub repositories.
Follow us on social media
Follow Author