Linux file system hierarchy: /, /etc, /var, /home, /tmp, /proc, /dev, /usr, /bin; file types

Linux Essentials Preparation · lesson 14 of 23 · 25 min

Linux File System Hierarchy

Linux uses a single unified directory tree starting at / (root). Everything — files, devices, processes — is represented as a file somewhere in this tree. Understanding the standard directories is essential for navigation and administration.

File Permissions

Every Linux file has three permission sets: owner (u), group (g), and others (o). Each set has three bits: read (r=4), write (w=2), execute (x=1).

Example: -rwxr-xr--

  • = regular file | rwx = owner can read/write/execute | r-x = group can read/execute | r– = others can only read

Octal notation

chmod 755 file = rwxr-xr-x7 (owner) = 4+2+1 = rwx | 5 (group) = 4+0+1 = r-x | 5 (others) = 4+0+1 = r-x

Permission Commands

Special Permissions

Flashcard Drill

/etc System configuration files — /etc/passwd, /etc/hosts, /etc/ssh/sshd_config. /var/log System log files — syslog, auth.log, messages. /tmp Temporary files — world-writable, cleared on reboot. chmod 755 rwxr-xr-x — owner full access, group/others read+execute. chmod 644 rw-r–r– — owner read/write, group/others read only. chown Changes file ownership — chown user:group file. SUID Set User ID — file runs with owner’s privileges regardless of who executes it. Sticky bit On /tmp — only the file owner can delete their own files. umask Default permission mask — subtracted from 666 (files) or 777 (dirs) for new files. /proc Virtual filesystem — real-time kernel and process information.

Worked Scenario: Permissions Analysis

Scenario

A file shows permissions: -rwsr-xr-x root root /usr/bin/passwd. What does the ‘s’ in the owner execute position mean, and why is it there?

Answer: SUID (Set User ID) bit. The ‘s’ in the owner execute position means the file runs with the owner’s privileges (root) regardless of who executes it. The passwd command needs to modify /etc/shadow (which is only writable by root), but regular users need to change their own passwords. SUID allows this safely — passwd runs as root temporarily, but only to update the calling user’s own password entry.

In octal, SUID is represented as 4 in the leading digit: chmod 4755 file = rwsr-xr-x.

Knowledge Check — 12 Questions

File System & Permissions (Linux Essentials)

Which directory contains system configuration files?

  • /bin
  • /var
  • /etc
  • /usr

Answer: /etc
/etc contains system-wide configuration files — /etc/passwd, /etc/hosts, /etc/ssh/sshd_config.

What does chmod 644 set?

  • rwxrwxrwx
  • rw-r–r–
  • rwxr-xr-x
  • r——–

Answer: rw-r–r–
644 = 6(rw-) for owner, 4(r–) for group, 4(r–) for others = rw-r–r–.

The directory that contains system log files is _____.

Answer: /var/log
/var/log contains system logs — syslog, auth.log, kern.log, etc.

Which command changes the owner of a file?

  • chmod
  • chgrp
  • chown
  • chperm

Answer: chown
chown changes file ownership — chown user:group filename.

What octal value represents rwx?

  • 5
  • 6
  • 7
  • 4

Answer: 7
rwx = read(4) + write(2) + execute(1) = 7.

The sticky bit on /tmp ensures:

  • Files are encrypted
  • Only the file owner can delete their own files
  • Files are executable by all
  • Files are hidden
  • Answer: Only the file owner can delete their own files

The sticky bit on a directory means only the file owner (or root) can delete their files.

/proc contains real files stored on disk.

  • True
  • False

Answer: False
/proc is a virtual filesystem — it provides real-time kernel and process information but contains no actual disk files.

SUID on an executable means:

  • Only root can run it
  • It runs with the file owner’s privileges
  • It is world-writable
  • It cannot be executed
  • Answer: It runs with the file owner’s privileges

SUID (Set User ID) causes the file to run with the owner’s privileges — e.g. passwd runs as root.

To add execute permission for the owner only, use chmod _____ script.sh.

Answer: u+x
chmod u+x adds execute permission for the user (owner) only.

Which directory is the root user’s home directory?

  • /home/root
  • /root
  • /admin
  • /superuser

Answer: /root
The root user’s home directory is /root — not /home/root.

A file shows -rwsr-xr-x. What does the “s” in the owner execute position indicate?

  • Sticky bit
  • SGID
  • SUID
  • Symbolic link

Answer: SUID
SUID (s in owner execute position) means the file runs with the owner’s privileges — used by /usr/bin/passwd.

Which directory contains temporary files that are cleared on reboot?

  • /var
  • /tmp
  • /opt
  • /mnt

Answer: /tmp
/tmp is world-writable and cleared on reboot — used for temporary files.


Previous lesson: Environment variables: PATH, HOME, USER, SHELL; export, env, set, unset
Back to Linux Essentials Preparation
Next lesson: Processes and hardware: ps, top, kill, systemctl, journalctl, hardware info commands