Navigating the Linux Filesystem
A practical introduction to Linux’s filesystem hierarchy, paths, filesystem objects, and commands for navigation and inspection.
The Filesystem Tree and Its Paths
The filesystem tree and its paths
Linux presents files and directories in one connected hierarchy that begins at the root directory, written /. Multiple filesystems can be mounted into this tree, so users navigate a unified structure even when different storage devices hold the data.
The Filesystem Hierarchy Standard (FHS) describes common directory purposes. These names provide useful clues about their usual roles:
/homeholds personal directories for ordinary users, such as/home/lee./rootis the root administrator’s home directory./etccontains system-wide configuration files./usrcommonly contains programs, libraries, and shared data./varholds data that changes during normal operation, such as logs and caches./tmpis for temporary files, which may be removed automatically./devcontains device files and certain kernel interfaces;/procexposes process and kernel information;/runholds runtime state./mntand/mediaare common locations for mounted filesystems and removable media.
These are conventions, not guarantees: distributions can vary, some directories may be symbolic links or combined with other locations, and mounted storage can appear elsewhere in the tree.
A path names a location. Slashes separate its components. An starts at /, as in /var/log; a relative path starts from the current working directory, as in notes/today.txt. The component . means the current directory, while .. means its parent. Thus, cd .. moves one directory upward.
Linux path names are case-sensitive: Report.txt and report.txt are different names. In the shell, is shorthand for the current user’s home directory; the shell expands it before running the command. For example, cd /Downloads usually enters that location. If a path contains spaces, quote it so the shell treats it as one path: cd "Project Files".
Filesystem Objects and File Types
Filesystem objects and file types
In Linux, “file” can mean any object in the filesystem, not only a document containing stored data. Common types include:
Regular files store text, images, programs, archives, and other data.
Directories contain entries naming other filesystem objects.
Symbolic links are paths that refer to other paths.
Device files represent character-oriented or block-oriented device interfaces.
Named pipes (FIFOs) and sockets are special objects used for communication between processes.
An extension is only part of a filename. A name ending in .txt does not prove that its contents are text or establish its actual type. Use file PATH to examine an object and report an inferred type or format.
A typical ls -l listing also gives a quick type clue in its first character: - indicates a regular file, d a directory, and l a . The characters after that describe permissions; they are separate from the type indicator.
Navigating, Listing, and Inspecting
Navigating, listing, and inspecting
Start by orienting yourself. pwd prints the current working directory. Use cd PATH to change it; cd .. moves to the parent, and cd with no path usually returns to the home directory. Then use ls to list directory contents. Options reveal more: ls -a includes hidden names, ls -l gives a detailed listing, and ls -lh uses human-readable sizes. Names beginning with . are hidden from ordinary ls, but they are still present; use ls -a to see them.
Different inspection commands answer different questions:
stat PATHshows metadata such as object type, size, and timestamps.file PATHreports an inferred type or format.PATHdisplays text page by page; pressqto quit.START -name PATTERNsearches below a starting directory for names matching a pattern.
For example, the supplied sequence first prints your location, lists its contents in detail (including hidden names, with human-readable sizes), moves to /var/log, and asks file to identify syslog:
pwd
ls -lah
cd /var/log
file syslog
Here, /var/log is an , so the cd destination does not depend on the starting directory. syslog is a relative path: after changing directories, it refers to an entry named syslog in the current directory. The final command reports an inferred type or format; it does not display the file’s text. To read a text file page by page, use PATH instead.
If a command reports “No such file or directory,” check spelling and capitalization, and check whether the path is absolute or relative. “Permission denied” is different: the path may exist, but your account may not be allowed to access it.
: An object in the filesystem used for communication between processes.