Navigating the file system hierarchy
Move around the tree confidently and know what lives in each top-level directory.
By Invicly Tech, , in Linux Administration (RHCSA-style). About 9 minutes to read.
In short
Linux has one directory tree starting at /, and the Filesystem Hierarchy Standard says what goes where. Knowing that configuration is in /etc, variable data in /var and user files in /home tells you where to look for almost anything. Tab completion, history and globbing make you fast.
Explained simply
On Linux every file lives in one tree of folders (directories) that starts at /, called the root. Disks, USB sticks and even network shares are attached somewhere inside this tree. To reach a file you give its path: the list of directories you walk through, separated by slashes.
A path that starts with / is absolute: it always means the same place, like a full postal address. A path without a leading / is relative: it starts from where you are now, like saying two doors down. pwd prints where you are, and cd moves you.
The top-level folders have fixed jobs. Settings are in /etc, logs and other changing data in /var, people's files in /home, and installed programs in /usr. Once you know this map, you can guess where almost anything is on a server you have never seen.
The shell also saves you typing. Tab completes names, the up arrow and Ctrl-R bring back old commands, and wildcards like *.log let one short pattern stand for many file names.
Press Play on a diagram to walk through it one step at a time.
- /etc
- System configuration
- fstab, passwd, ssh/sshd_config
- /var
- Logs in /var/log
- Spools, caches, databases
- /home and /root
- User home directories
- root's home is /root
- /usr
- Programs in /usr/bin
- Libraries and docs
- /dev, /proc, /sys
- Device files
- Kernel and process information
- /tmp and /run
- Temporary files
- Runtime state, cleared at boot
- Step 1Start at /var/www
Relative paths begin at the current directory
- Step 2..
Go up to /var
- Step 3log
Enter /var/log (needs x permission)
- Step 4app.log
Final result: /var/log/app.log
In depth
How the kernel follows a path
When you open /var/log/messages, the kernel starts at / and looks up each name in turn: var inside /, then log inside var, then messages inside log. To pass through a directory you need execute (x) permission on it; to list its contents you need read (r). That is why a single locked parent directory blocks everything below it.
Every directory contains two special entries: . is the directory itself and .. is its parent, so ../logs means go up one level, then into logs. Symbolic links are followed along the way. pwd usually shows the path you typed (the logical path); pwd -P and realpath show the real location after links are resolved.
- cd with no argument goes to your home directory
- cd - jumps back to the previous directory
- ~ means your home, ~alice means alice's home
- realpath file prints the full resolved path
Not every directory is on disk
Some top-level directories are real files on disk, but others are generated on the fly. /proc and /sys are views into the kernel: /proc/cpuinfo or /proc/1234/status are produced when you read them and use no disk space. /dev holds device files, such as /dev/sda for the first disk, created by the kernel and udev at boot. /run is a tmpfs, a file system in RAM, so it is empty after every reboot.
On modern RHEL and Ubuntu, /bin, /sbin and /lib are just symbolic links into /usr, so /bin/ls and /usr/bin/ls are the same file. On RHEL, systemd-tmpfiles cleans files in /tmp that have not been used for 10 days and in /var/tmp after 30 days, so never keep anything important in either.
- /etc: configuration
- /usr: programs and libraries
- /var: logs, caches, databases
- /home and /root: user files
- /proc: processes and kernel info
- /sys: devices and drivers
- /dev: device files
- Nothing is stored on disk
- /run: PID files, sockets
- /dev/shm: shared memory
- Cleared at every boot
- Fast but limited by RAM
Globbing and brace expansion, exactly
The shell rewrites your command line before the program ever sees it. A glob matches existing file names: * matches any text, ? matches one character, and [abc] or [0-9] match one character from a set. A leading dot is special: * does not match hidden files such as .bashrc. If nothing matches, bash passes the pattern unchanged, so ls *.bak shows an error that mentions the literal *.bak.
Brace expansion is different: it makes strings whether or not files exist. file{1..3} becomes file1 file2 file3, {01..10} keeps the zero padding, and cp app.conf{,.bak} becomes cp app.conf app.conf.bak. Quotes switch all of this off: ls "*.log" looks for a file literally named *.log.
- 1Brace expansion
a{1,2} becomes a1 a2
- 2Tilde, variables, $(...)
~ and $HOME replaced by values
- 3Word splitting
Unquoted results split on spaces
- 4Globbing
*.log replaced by matching names
- 5Quote removal
Quotes are stripped
- 6Command runs
It only sees the final words
History and line editing that save hours
bash keeps your commands in memory and writes them to ~/.bash_history when the shell exits. HISTSIZE sets how many are kept in memory and HISTFILESIZE how many are kept in the file. Ctrl-R searches backwards as you type; press Ctrl-R again for older matches. !! repeats the last command, so sudo !! reruns it with sudo. !$ and Alt-. insert the last argument of the previous command.
A few editing keys work in every bash prompt: Ctrl-A jumps to the start of the line, Ctrl-E to the end, Ctrl-W deletes the previous word and Ctrl-U deletes back to the start. Install the bash-completion package and Tab also completes command options, systemctl unit names and package names.
- HISTCONTROL=ignoreboth skips duplicates and lines starting with a space
- history 20 shows the last 20 commands
- !123 reruns command number 123 from history
- Tab twice lists all possible completions
Learn it in 4 short steps
About 40m each. Track them with a timer in your plan.
- 1Use absolute and relative paths~40m
- 2Explain /etc, /var, /home, /usr, /tmp~40m
- 3Use tab completion and history~40m
- 4Use globbing and brace expansion~40m
Key points
- Absolute paths start with /; relative paths start from the current directory.
- cd - returns to the previous directory and cd alone goes home.
- Tab completes names; Ctrl-R searches command history.
- Globs like *.log and file{1..3} are expanded by the shell before the command runs.
Key terms
Tap a card to flip it. 0/5 known
Examples
pwd
cd /var/log && ls -lt | head
cd -
ls /etc/*.conf
mkdir -p ~/lab/{data,logs,scripts}
history | grep dnfMove around, list newest logs and create a directory tree in one command.
Preview a wildcard before deleting
You want to delete old rotated logs named app.log.1 to app.log.9 in /var/log/myapp but keep app.log. Step 1: put echo in front so the shell shows you what the glob expands to, without running anything. Step 2: check the list carefully. Step 3: run the real command with the same pattern. The ? matches exactly one character, so app.log itself (no suffix) and app.log.10 are not touched.
cd /var/log/myapp
ls
# app.log app.log.1 app.log.2 app.log.10 app.log.3
echo rm app.log.?
# rm app.log.1 app.log.2 app.log.3
sudo rm app.log.?Find out where a command really lives
Someone says python3 is broken. Step 1: type -a shows every match in your PATH and whether it is an alias or function. Step 2: realpath follows symbolic links to the real file. Step 3: on a RHEL-family system, rpm -qf tells you which package owns the file (on Ubuntu, dpkg -S does the same). Now you know exactly which binary runs.
type -a python3
# python3 is /usr/bin/python3
realpath /usr/bin/python3
# /usr/bin/python3.9
rpm -qf /usr/bin/python3.9 # Ubuntu: dpkg -S /usr/bin/python3.12
echo "$PATH" | tr ':' '\n' # the directories searched, in orderQuick reference
- pwd -P shows the real directory after following symbolic links
- cd - goes back to the previous directory; cd alone goes home
- echo rm *.tmp previews what a glob expands to before you run it
- cp file{,.bak} makes a quick backup copy called file.bak
- mkdir -p ~/lab/{data,logs,scripts} builds a small tree in one command
- Ctrl-R searches history; sudo !! reruns the last command with sudo
- /proc and /sys use no disk; /run and /dev/shm are in RAM and cleared at boot
- type -a cmd shows every alias, function and file that matches cmd
Quick quiz
Pick an answer to see if you're right and why.
Practice exercises
Try each one yourself first. Use the hint if you get stuck, then compare with the solution.
- Exercise 1easy
Starting from your home directory, go to /var/log, list the five most recently changed files, then return to where you were with one short command.
- Exercise 2medium
Create ~/lab/2026/{01..12} (one folder per month), each with an empty notes.txt, using as few commands as possible. Then count the files.
- Exercise 3hard
Show which top-level directories are separate mounts and what kind of file system each one is, so you can tell disk, RAM and kernel-made directories apart.
Check yourself
Answer in your head, reveal, then be honest with yourself.
Feel confident about this topic?
Frequently asked questions
- What is the difference between /usr/bin and /usr/local/bin?
- /usr/bin is managed by the package manager. /usr/local/bin is for programs you install by hand, so updates never overwrite them; it usually comes earlier in PATH.
- Why does ls not show files starting with a dot?
- Names starting with a dot are hidden by convention. Use ls -a to see them, or ls -A to see them without . and ..
- Where should I put my own application on a server?
- Common choices are /opt/appname for self-contained software and /srv for data a service serves. Its config goes in /etc and its logs and state under /var.
- Is /tmp safe for files I need tomorrow?
- No. /tmp may be cleared at boot or cleaned automatically after some days, depending on the distribution. Use your home directory or /var/tmp only for short-lived work.