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:

  1. Is the user the owner?
  2. Else, is the user part of the group?
  3. 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 -l

Example:

-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

PartMeaning
-File type (- file, d directory)
rwxOwner permissions
rwxGroup permissions
r-xOthers permissions

👉 As a DevOps engineer, you should be able to read this instantly without thinking.


2️⃣ Permission Symbols

Each permission block has 3 characters:

SymbolValueMeaning
r4Read
w2Write
x1Execute
-0No 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

CommandMeaningUse Case
chmod 755rwxr-xr-xscripts, executables
chmod 644rw-r—r—config files
chmod 700rwx------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

umask

Explanation

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

TypeDefault
File666
Directory777

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.txt

Explanation

Changes the owner and optionally group of a file.


chgrp

sudo chgrp devops file.txt

Explanation

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.tar

Explanation

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.gz

Adds gzip compression.


🔹 gzip

gzip file.txt
gunzip file.txt.gz
zcat file.txt.gz

Explanation

Compresses individual files.

👉 gzip is also installed by default.


🔹 zip / unzip

zip archive.zip file1 file2
unzip archive.zip

Important 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 🚀