Master Linux Filesystem Hierarchy: Essential Directories and Command Guide
This guide explains the Linux filesystem hierarchy, detailing the purpose of each standard directory, providing practical command‑line examples, and offering tips for managing configuration files, logs, temporary data, and custom services to improve system administration.
Understanding the Linux filesystem hierarchy is crucial for system administrators and developers, as it defines how files and directories are organized and accessed.
Linux Filesystem Hierarchy Overview
The hierarchy starts at the root directory ( /) and expands into multiple subdirectories, each serving specific roles.
Root and Core Directories
/bin and /sbin Directories
/bincontains essential binaries needed for system boot and basic operations, while /sbin holds binaries used primarily by the superuser for system management.
# Example: List files in /bin
ls /bin/etc Directory
/etcstores system configuration files that are vital for the proper functioning of the OS and applications.
# Example: View common configuration files in /etc
ls /etc/home Directory
/homeis the base for user home directories, with each user having a separate subdirectory.
# Example: Show user directories under /home
ls /homeSystem Library Directories
/lib and /lib64 Directories
These directories contain shared libraries required for system boot and runtime execution of programs.
# Example: List shared libraries in /lib
ls /libUser‑Related Directories
/root Directory
/rootis the home directory of the superuser (root).
# Example: View contents of /root
ls /rootDevice Files and Mount Points
/dev Directory
/devholds device files that provide interfaces to hardware devices.
# Example: List device files in /dev
ls /dev/mnt and /media Directories
These are typically used as temporary mount points for external filesystems or storage devices.
# Example: Show mount points under /mnt
ls /mntProcess Information Directory
/proc Directory
/procis a virtual filesystem exposing kernel, process, and system information dynamically.
# Example: Display CPU information from /proc
cat /proc/cpuinfoLog Files Directory
/var/log Directory
/var/logcontains system log files that record the status of the system and services.
# Example: View recent system log entries
tail /var/log/syslogTemporary Files Directory
/tmp Directory
/tmpstores temporary files and is usually cleared on reboot.
# Example: Clean up temporary files
rm -rf /tmp/*Other Important Directories
/opt Directory
/optis commonly used for optional or third‑party applications.
# Example: List optional applications
ls /opt/srv Directory
/srvholds data for specific services.
# Example: List service‑related data
ls /srvUser Configuration Files
/etc/passwd and /etc/group
These files store user account and group information respectively.
# View user accounts
cat /etc/passwd
# View groups
cat /etc/groupSystem Boot Directory
/boot Directory
/bootcontains the bootloader and kernel images.
# Example: List boot files
ls /bootUser Configuration Directory
~/.config Directory
User-specific configuration files are typically stored under ~/.config.
# Example: List user config files
ls ~/.configSecure Cleanup of Temporary Files
Regular /tmp Cleanup
Periodically cleaning /tmp is good practice; it can be automated with a cron job.
# Edit crontab to add cleanup job
crontab -e
# Add line:
# 0 0 * * * /bin/rm -rf /tmp/*Backing Up Important Configuration
Backup /etc Directory
Regular backups of /etc prevent loss of critical configuration files.
# Create a backup archive of /etc
tar czf /backup/etc_backup_$(date +%Y%m%d).tar.gz /etcCreating Custom Directory Structures
/opt/myapp Directory
For custom applications or scripts, create subdirectories under /opt.
# Create custom application directory
sudo mkdir /opt/myappCustom System Services
/etc/systemd/system Directory
Define custom systemd services by placing unit files in /etc/systemd/system.
# Create a new service unit file
sudo nano /etc/systemd/system/my_service.service # my_service.service
[Unit]
Description=My Custom Service
[Service]
ExecStart=/opt/myapp/my_service
Restart=always
[Install]
WantedBy=default.targetConclusion
By mastering the Linux filesystem hierarchy, you gain a clear understanding of standard directories, learn how to manage users, configuration files, logs, and services, and acquire practical skills for customizing and maintaining a stable, maintainable Linux system.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
