The directory tree
Linux organises every file, device, and mounted disk into a single tree starting at /. Knowing the standard layout tells you where everything lives.
One tree, many disks
Unlike systems with drive letters, Linux has a single directory tree rooted at /, the root directory. Additional disks, partitions, network shares, and USB drives are mounted onto directories within that tree, so a second disk might appear at /data. Paths use forward slashes: /home/ana/notes.txt.
The Filesystem Hierarchy Standard
The Filesystem Hierarchy Standard (FHS) describes conventional locations. /bin and /sbin hold essential commands; /usr holds most installed software, libraries, and documentation; /etc holds system configuration; /home holds users' directories; /root is the administrator's home; /var holds variable data such as logs, caches, and spools; /tmp holds temporary files; /boot holds kernels and boot files; and /opt holds optional add-on software.
Virtual and device directories
Some directories are not ordinary storage. /proc and /sys are virtual file systems exposing kernel and process information; /dev contains device files representing hardware such as disks and terminals; /run holds runtime data such as process IDs and sockets, cleared at each boot. Many distributions now merge /bin into /usr/bin, keeping /bin as a link.
Absolute and relative paths
An absolute path starts at the root, such as /etc/hosts. A relative path starts from the current working directory: if you are in /home/ana, docs/report.txt means /home/ana/docs/report.txt. The special names . (current directory) and .. (parent directory) and ~ (your home directory, expanded by the shell) make navigation easier.
Navigating
pwd prints the current directory; cd changes it (cd with no argument returns home, cd - returns to the previous directory); ls lists contents, with ls -l showing details, ls -a including hidden files whose names start with a dot, and ls -lh showing human-readable sizes. tree, if installed, draws the directory hierarchy.
Working with files
cp copies files (cp -r copies directories recursively); mv moves or renames; rm removes files (rm -r removes directories and their contents, with no recycle bin, so care is essential); mkdir creates directories (mkdir -p creates parents as needed); touch creates empty files or updates timestamps. cat, less, head, and tail display file contents, and tail -f follows a growing log.
Finding files
find searches the tree by name, type, size, time, owner, and more, for example find /var/log -name '*.log' -mtime -1 lists log files modified in the last day. locate searches a prebuilt database very quickly. which and type show which program a command name runs, and file identifies a file's type from its contents rather than its name.
Worked example
In /home/ana, the command mkdir -p projects/site/css creates three nested directories. cd projects/site moves into them; cp ~/Downloads/style.css css/ copies a file into the new css directory; ls -l css shows its size and permissions; and cd ../.. returns to /home/ana. find ~/projects -name '*.css' then lists every CSS file under the projects directory.
Key takeaways
Linux uses one tree rooted at /, mounting other storage onto directories. The FHS defines locations: /usr for software, /etc for configuration, /home for users, /var for logs and changing data, /tmp for temporary files, and /boot for kernels. /proc, /sys, /dev, and /run are virtual or special. Absolute paths start at /; relative paths start from the current directory, with ., .., and ~ as shortcuts. pwd, cd, and ls navigate; cp, mv, rm, mkdir, and touch manage files, and rm has no undo. find, locate, which, and file help locate and identify files.
Flashcard
/, the top of the tree
Check your understanding
Where would you normally look for a service's configuration file on a Linux system?
