Permissions
Linux is a multi-user operating system with a robust file permission system to control access to files and directories. Every file and directory has an owner, a group, and access rights defined for the owner, the group, and all other users (others). These permissions determine who can read, write, or execute a file or directory.
Types of Permissions
There are three basic permission types:
- Read (r): Ability to view the contents of a file or list a directory.
- Write (w): Ability to modify a file or add/delete files in a directory.
- Execute (x): Ability to run a file as a program or enter a directory.
Permission Values Table
| Permission | Symbol | Numeric Value | File Meaning | Directory Meaning |
|---|---|---|---|---|
| None | - | 0 | No access | No access |
| Execute | x | 1 | Run a file | Enter or traverse directory |
| Write | w | 2 | Modify file contents | Add/delete files |
| Read | r | 4 | View file contents | List contents |
These values are combined using addition. For example, read + write = 4 + 2 = 6.
Permission Representation
Linux permissions are shown with ls -l. Example:
-rwxr-xr--This means:
- File type:
-(regular file) - Owner:
rwx(read, write, execute) - Group:
r-x(read, execute) - Others:
r--(read only)
Ownership and Groups
Every file or directory has:
- Owner (user who created it)
- Group (user group associated with the file)
- Others (all other users on the system)
Permissions are defined separately for each of these.
Permission Commands and Syntax
chmod – Change file or directory permissions
Symbolic mode example:
chmod u+x script.shOctal mode example:
chmod 755 script.shchown – Change ownership (user or user:group)
chown alice file.txt
chown alice:devs file.txtchgrp – Change group ownership
chgrp devs file.txtCommand Summary Table
| Command | Purpose | Example |
|---|---|---|
ls -l | View file permissions | ls -l |
chmod | Modify permissions | chmod 644 file.txt |
chmod -R | Change permissions recursively | chmod -R 755 /project |
chown | Change file owner | chown alice file.txt |
chown user\:group | Change owner and group | chown alice:devs file.txt |
chgrp | Change group only | chgrp devs file.txt |
Last updated on