π Linux/Unix: File Permissions & ls -l Explained β Read, Write & Execute Control
π§² Introduction β Why Learn Linux/Unix File Permissions?
Every file and directory in Linux/Unix has a set of permissions that determine who can read, write, or execute them. Understanding file permissions is critical for system security, collaboration, and automation. The ls -l command gives a clear view of permissions, ownership, and moreβall in one place.
π― In this guide, youβll learn:
- How to read and understand file permission strings using
ls -l - What read, write, and execute mean for users, groups, and others
- Permission breakdowns for files vs. directories
- Real examples of permission control
π Understanding ls -l Output
π§ͺ Example:
ls -l
π‘ Output:
-rw-r--r-- 1 user group 1024 Jun 15 12:00 notes.txt
Breakdown:
| Part | Meaning |
|---|---|
- | Type (- = file, d = directory, l = link) |
rw- | Owner permissions (read, write) |
r-- | Group permissions (read only) |
r-- | Others permissions (read only) |
1 | Number of hard links |
user | File owner |
group | Group owner |
1024 | File size in bytes |
Jun 15 12:00 | Last modification date/time |
notes.txt | File name |
π Permission Types
| Symbol | Meaning | Applies to |
|---|---|---|
r | Read (view content) | File/Directory |
w | Write (edit/remove) | File/Directory |
x | Execute (run file or access dir) | File/Directory |
For Directories:
rβ List contentswβ Create/delete filesxβ Enter the directory
π₯ User Classes
| Class | Symbol | Description |
|---|---|---|
| Owner | u | User who owns the file |
| Group | g | Group associated with the file |
| Others | o | All other users |
| All | a | Everyone (u + g + o) |
π’ Numeric (Octal) Representation of Permissions
| rwx | Binary | Octal |
|---|---|---|
| rwx | 111 | 7 |
| rw- | 110 | 6 |
| r-x | 101 | 5 |
| r– | 100 | 4 |
| -wx | 011 | 3 |
| -w- | 010 | 2 |
| –x | 001 | 1 |
| — | 000 | 0 |
π§ͺ Example:
-rwxr-xr-- β Owner=7, Group=5, Others=4 β 754
π οΈ Modify Permissions with chmod
β Syntax:
chmod [permissions] filename
π§ͺ Examples:
chmod 755 script.sh # rwxr-xr-x
chmod u+x file.sh # Add execute to owner
chmod go-w file.txt # Remove write from group and others
π View and Change Ownership
View Ownership:
ls -l
Change Owner:
sudo chown user file.txt
Change Group:
sudo chgrp groupname file.txt
π Summary β Recap & Next Steps
Mastering Linux file permissions helps protect sensitive data, control access levels, and prevent accidental changes. Using ls -l gives you full visibility into permissions, ownership, and file metadata.
π Key Takeaways:
- Use
ls -lto check file types, permissions, owners, and size. - Permissions are divided among user, group, and others with
r,w, andx. - Numeric (
chmod 755) and symbolic (chmod u+x) modes both work. - Use
chownandchgrpto manage file ownerships.
β FAQs
β What does drwxr-xr-x mean?
β
It’s a directory (d) with permissions: owner (read/write/execute), group (read/execute), others (read/execute).
β How do I make a file executable?
β
Use:
chmod +x filename.sh
β How can I change file permissions recursively?
β
Use:
chmod -R 755 myfolder/
β What’s the safest permission for scripts?
β
Use chmod 755 to allow execute by all, but write only by the owner.
β Can a group member modify a file?
β
Only if the group has write permission (w), and the user belongs to that group.
Share Now :
