_____ _ ___ _________ __ |_ _|__ _ __ _ __ ___ (_)_ __ __ _| \ \ / / ____\ \/ / | |/ _ \ '__| '_ ` _ \| | '_ \ / _` | |\ \ / /| _| \ / | | __/ | | | | | | | | | | | (_| | | \ V / | |___ / \ |_|\___|_| |_| |_| |_|_|_| |_|\__,_|_| \_/ |_____/_/\_\
In the Linux operating system, everything is a file. This statement summarizes the fundamental philosophy of Linux. Your documents, programs, and even hardware devices are all represented as files or directories within the file system. Unlike Windows, Linux does not use drive letters like C: or D:. Instead, it uses a tree-like hierarchy starting from a single root directory.
This hierarchy is defined by a standard called the Filesystem Hierarchy Standard (FHS). The FHS specifies which directory is used for what purpose, ensuring consistency across Linux distributions. Thanks to this standard, the directory structure you learn on Ubuntu also applies to Fedora, Debian, or Arch Linux.
At the very top of the Linux file system sits the root directory, represented by a single forward slash (/). All files and directories branch out from this point. The root directory is like the trunk of the tree; all other directories are its branches. Only the root user (superuser) can write directly to the root directory.
$ ls /
bin boot dev etc home lib media mnt opt proc root run sbin srv sys tmp usr var
The /home directory contains a separate subdirectory for each regular user on the system. For example, a user named "ali" would have a home directory at /home/ali. Personal documents, downloads, configuration files, and desktop content are all stored here.
$ ls /home/ali
Documents Downloads Desktop Music Pictures .bashrc .config
You can use the tilde (~) symbol as a shortcut to your home directory. Typing cd ~ or just cd takes you to your home directory. It is also accessible as the $HOME environment variable.
The /etc directory houses the system's configuration files. Its name comes from "et cetera" (and so on), though it is also interpreted as "Editable Text Configuration" today. Network settings, user account information, service configurations, and security policies are all kept here.
$ ls /etc
apache2 bash.bashrc crontab fstab hostname hosts network passwd shadow ssh sudoers
Some important configuration files include:
Editing these files requires root privileges. An incorrect edit can render the system unbootable, so always create a backup before making changes.
The /var directory holds data whose size changes continuously. Its name comes from "variable." Log files, email queues, database files, and web server content are stored here.
$ ls /var
backups cache lib lock log mail opt run spool tmp www
syslog, auth.log, and kern.log reside here.The /tmp directory holds temporary files created by programs. Files in this directory are usually deleted automatically when the system reboots. All users can write to this directory, but for security the sticky bit is set, meaning each user can only delete files they created themselves.
$ ls -ld /tmp
drwxrwxrwt 15 root root 4096 Jan 10 14:30 /tmp
The "t" at the end of the permissions indicates the sticky bit.
The /usr directory stands for "Unix System Resources" and contains the vast majority of user-installed programs. Programs beyond the essential tools that ship with the operating system are typically installed here.
$ ls /usr
bin include lib lib64 local sbin share src
The /bin directory contains commands essential for the system to function: ls, cp, mv, rm, cat, echo, and so on. These commands must be accessible even in single-user mode.
The /sbin directory holds commands needed for system administration: fdisk, mkfs, iptables, reboot, etc. These commands typically require root privileges.
$ ls /bin
bash cat cp date echo grep ls mkdir mv pwd rm sh touch
$ ls /sbin
fdisk fsck halt ifconfig init iptables mkfs reboot shutdown
In modern Linux distributions, /bin and /sbin are usually symbolic links to /usr/bin and /usr/sbin.
The /opt directory is reserved for third-party software installations. Applications like Google Chrome, Visual Studio Code, and Zoom are typically installed here. Each application gets its own subdirectory: /opt/google/chrome, /opt/vscode, and so on.
The /dev directory contains special files that represent hardware devices. It is the most concrete example of the Linux philosophy that "everything is a file." Hard drives, USB drives, terminals, and even random number generators exist here as files.
$ ls /dev
sda sda1 sda2 sdb tty tty0 null zero random urandom
The /proc directory is a virtual file system; it does not physically occupy space on disk. It provides real-time information about running processes, CPU details, memory status, and kernel parameters.
$ cat /proc/cpuinfo # CPU information
$ cat /proc/meminfo # Memory usage
$ ls /proc/1234 # Information about process with PID 1234
$ cat /proc/version # Kernel version
In Linux, you can refer to a file or directory in two ways:
A complete path starting from the root directory (/). It always points to the same location, regardless of your current directory.
$ cat /home/ali/Documents/notes.txt
$ cd /var/log
A path defined relative to your current directory. . represents the current directory, and .. represents the parent directory.
$ cd Documents # Go to the Documents folder in the current directory
$ cat ./notes.txt # Read a file in the current directory
$ cd ../Pictures # Go up one level, then into Pictures
Once you understand the file system structure, here are some practical methods for navigating efficiently:
$ cd - # Return to the previous directory
$ pushd /var/log # Push current directory to stack and go to /var/log
$ popd # Return to the last directory on the stack
$ find / -name "*.conf" -type f # Find all .conf files
Understanding the Linux file system structure is the foundation for working effectively on the command line. Each directory has a specific purpose, and knowing these purposes tells you where to look for your files and where to edit system configurations.