Fundamentals 9 min read

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.

Liangxu Linux
Liangxu Linux
Liangxu Linux
Master Linux Filesystem Hierarchy: Essential Directories and Command Guide

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

/bin

contains 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

/etc

stores 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

/home

is the base for user home directories, with each user having a separate subdirectory.

# Example: Show user directories under /home
ls /home

System 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 /lib

User‑Related Directories

/root Directory

/root

is the home directory of the superuser (root).

# Example: View contents of /root
ls /root

Device Files and Mount Points

/dev Directory

/dev

holds 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 /mnt

Process Information Directory

/proc Directory

/proc

is a virtual filesystem exposing kernel, process, and system information dynamically.

# Example: Display CPU information from /proc
cat /proc/cpuinfo

Log Files Directory

/var/log Directory

/var/log

contains system log files that record the status of the system and services.

# Example: View recent system log entries
tail /var/log/syslog

Temporary Files Directory

/tmp Directory

/tmp

stores temporary files and is usually cleared on reboot.

# Example: Clean up temporary files
rm -rf /tmp/*

Other Important Directories

/opt Directory

/opt

is commonly used for optional or third‑party applications.

# Example: List optional applications
ls /opt

/srv Directory

/srv

holds data for specific services.

# Example: List service‑related data
ls /srv

User 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/group

System Boot Directory

/boot Directory

/boot

contains the bootloader and kernel images.

# Example: List boot files
ls /boot

User Configuration Directory

~/.config Directory

User-specific configuration files are typically stored under ~/.config.

# Example: List user config files
ls ~/.config

Secure 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 /etc

Creating Custom Directory Structures

/opt/myapp Directory

For custom applications or scripts, create subdirectories under /opt.

# Create custom application directory
sudo mkdir /opt/myapp

Custom 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.target

Conclusion

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.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxDirectory StructureFilesystem
Liangxu Linux
Written by

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

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.