Day 07 — File Management & Permissions in Linux
🎯 Goal
This chapter builds a deep understanding of how Linux controls file access, ownership, and movement across systems.
File permissions are not just a feature — they are the foundation of Linux security and multi-user design.
🧠 Mental Model
Every file in Linux follows a strict access model:
User (Owner) → Group → Others → Permissions
Whenever a user tries to access a file, Linux evaluates:
- Is the user the owner?
- Else, is the user part of the group?
- Else, treat as “others”
Then permissions are applied.
This model is why Linux systems are secure, predictable, and scalable.
1️⃣ Viewing Permissions — ls -l
ls -lExample:
-rwxrwxr-x 1 user group 4096 Jan 1 file.sh
Explanation
This command gives you a complete snapshot of file metadata.
You can immediately see:
- who owns the file
- which group it belongs to
- what permissions are applied
Breakdown
| Part | Meaning |
|---|---|
| - | File type (- file, d directory) |
| rwx | Owner permissions |
| rwx | Group permissions |
| r-x | Others permissions |
👉 As a DevOps engineer, you should be able to read this instantly without thinking.
2️⃣ Permission Symbols
Each permission block has 3 characters:
| Symbol | Value | Meaning |
|---|---|---|
| r | 4 | Read |
| w | 2 | Write |
| x | 1 | Execute |
| - | 0 | No permission |
Deep Understanding
Permissions are internally stored as binary bits, but exposed as readable symbols.
This abstraction allows both human readability and programmatic control.
3️⃣ chmod — Deep Understanding
Core Concept
Permissions are calculated using:
r = 4, w = 2, x = 1
Each digit is a sum of these values.
Example: chmod 775
775 → rwxrwxr-x
Explanation
- First digit (7) → owner → full access (4+2+1)
- Second digit (7) → group → full access
- Third digit (5) → others → read + execute
This allows:
- owner and group → full control
- others → limited access
Common Patterns
| Command | Meaning | Use Case |
|---|---|---|
| chmod 755 | rwxr-xr-x | scripts, executables |
| chmod 644 | rw-r—r— | config files |
| chmod 700 | rwx------ | private data |
Why chmod Matters
Incorrect permissions can:
- expose sensitive data
- break applications
- cause security vulnerabilities
Correct permissions ensure:
- controlled access
- system stability
- secure deployments
4️⃣ umask — Default Permissions
umaskExplanation
umask defines the default permission mask applied when new files are created.
Linux does NOT assign permissions directly. Instead:
Default permission - umask = final permission
Defaults
| Type | Default |
|---|---|
| File | 666 |
| Directory | 777 |
Example
umask = 022
Result
- File → 666 - 022 = 644
- Directory → 777 - 022 = 755
Why this matters
- Prevents accidental write access to others
- Enforces security baseline automatically
- Critical in multi-user systems
5️⃣ Ownership — chown & chgrp
chown
sudo chown user file.txt
sudo chown user:group file.txtExplanation
Changes the owner and optionally group of a file.
chgrp
sudo chgrp devops file.txtExplanation
Changes only the group ownership.
Why Ownership Matters
Ownership determines:
- who can modify files
- which services can access resources
- how applications interact with files
6️⃣ Compression & Archiving
Compression reduces file size and is heavily used in:
- backups
- log storage
- file transfers
🔹 tar — Archiving Tool
tar -cvf archive.tar dir/
tar -xvf archive.tarExplanation
tar bundles multiple files into a single archive.
👉 Important:
- tar is installed by default on almost all Linux systems
Compress with tar
tar -czvf archive.tar.gz dir/
tar -xzvf archive.tar.gzAdds gzip compression.
🔹 gzip
gzip file.txt
gunzip file.txt.gz
zcat file.txt.gzExplanation
Compresses individual files.
👉 gzip is also installed by default.
🔹 zip / unzip
zip archive.zip file1 file2
unzip archive.zipImportant Note
zip is NOT always installed by default.
Install if needed:
sudo apt install zip unzip🧠 Key Takeaways
- Permissions define security boundaries
- chmod uses binary logic (4+2+1)
- umask controls default behavior
- ownership defines control
- tar & gzip are default tools
- zip may require installation
- scp copies, rsync syncs efficiently
✅ Outcome
You can now:
- Interpret and set permissions confidently
- Understand ownership deeply
- Control default file behavior
- Compress and archive files
- Transfer and sync data across systems
Next → Linux Networking Commands 🚀