Linux File System Hierarchy
Understanding the Linux file system hierarchy is essential for DevOps engineers managing cloud, container, and multi-user environments. This guide provides a practical overview, real-world examples, and best practices for navigating and using the Linux directory structure.
Key Directories and Their Purpose
| Directory | Purpose & Examples |
|---|---|
/ |
Root of the file system. All other directories branch from here. Only root can write here. |
/root |
Home directory for the root user. |
/etc |
System-wide configuration files. E.g., /etc/resolv.conf, /etc/logrotate.conf. |
/home |
User home directories. E.g., /home/alice, /home/bob. |
/var |
Variable data: logs, spools, cache. E.g., /var/log/syslog. |
/opt |
Optional/add-on application software. E.g., /opt/google/chrome. |
/lib, /lib64 |
Essential shared libraries for binaries in /bin and /sbin. 64-bit libraries in /lib64. |
/tmp |
Temporary files, cleared on reboot. |
/mnt |
Temporary mount point for filesystems. |
/srv |
Site-specific data served by the system (web, FTP, VCS). |
/usr |
User programs, libraries, docs. E.g., /usr/bin, /usr/local, /usr/src. |
/dev |
Device files (disks, terminals, USB). E.g., /dev/sda, /dev/null. |
/proc |
Virtual filesystem for process and kernel info. E.g., /proc/cpuinfo. |
/bin |
Essential user binaries (e.g., ls, cp). |
/sbin |
System binaries for admin tasks (e.g., reboot, fdisk). |
/media |
Mount points for removable media (CD-ROM, USB). |
/boot |
Boot loader files (kernel, initrd, grub). |
Real-World DevOps Examples
1. Mounting Cloud Storage (AWS, Azure, GCP)
# Mount an EBS volume to /mnt/data (AWS EC2)
sudo mkfs.ext4 /dev/xvdf
sudo mkdir -p /mnt/data
sudo mount /dev/xvdf /mnt/data
2. Managing Logs in /var
# View system logs
sudo tail -f /var/log/syslog
# Rotate logs manually
sudo logrotate /etc/logrotate.conf
3. Using /etc for Configuration Management
# Use Ansible to manage /etc/ssh/sshd_config
- name: Ensure SSH root login is disabled
ansible.builtin.lineinfile:
path: /etc/ssh/sshd_config
regexp: '^PermitRootLogin'
line: 'PermitRootLogin no'
4. Container Volumes
# Kubernetes pod mounting /data from host
volumes:
- name: data-volume
hostPath:
path: /mnt/data
type: Directory
Best Practices
- Never store application data in
/tmpor/var/tmpfor production workloads. - Use
/optor/usr/localfor custom or third-party software. - Automate configuration management for
/etcusing tools like Ansible or Terraform. - Regularly monitor
/varfor log growth to avoid disk space issues. - Use
/mntand/mediafor temporary and removable storage only.
References
Tip: In cloud and container environments, always use persistent storage for important data and automate mount/configuration steps in your deployment pipeline.