Chapter Objective
Describe the purpose of key directories in the Linux filesystem hierarchy, and navigate, create, copy, move, and locate files and directories from the command line.
Key Commands
pwdcdlsfilemkdircpmvrmlnfind
Describe the purpose of key directories in the Linux filesystem hierarchy, and navigate, create, copy, move, and locate files and directories from the command line.
pwdcdlsfilemkdircpmvrmlnfindLinux organizes all files into a single tree, starting at the root directory (/). Every file and directory on the system — regardless of which physical disk or partition it lives on — has a location somewhere under /. Red Hat Enterprise Linux follows the Filesystem Hierarchy Standard (FHS), a convention shared across most Linux distributions for what belongs where.
| Directory | Purpose |
|---|---|
/ | The root directory; top of the entire tree |
/bin, /usr/bin | Essential user command binaries |
/sbin, /usr/sbin | System administration binaries |
/etc | System-wide configuration files |
/var | Variable data: logs, spool files, caches |
/home | Regular users' home directories |
/root | The root user's home directory |
/opt | Optional third-party software packages |
/tmp | Temporary files, cleared periodically |
/dev | Device files representing hardware |
/proc, /sys | Virtual filesystems exposing kernel and process information |
/mnt, /media | Mount points for temporary or removable filesystems |
man hier for the full, authoritative description of the Filesystem Hierarchy Standard directly on the system.
Every process — including your shell — has a current working directory. Paths you type are interpreted relative to it, unless they start with /.
# Print the current working directory pwd # Change to an absolute path — always starts from root cd /etc/ssh # Change to a relative path — starts from where you are now cd ../ssh # Shortcuts cd ~ # your home directory cd # also your home directory (no argument) cd - # the previous directory cd .. # the parent directory cd . # the current directory (rarely useful with cd itself)
. refers to itself, and .. refers to its parent. Many commands, not just cd, accept these.
# Basic listing of the current directory ls # Long format: permissions, owner, size, modification time ls -l # Include hidden files (those starting with a dot) ls -a # Combine common options ls -la # Human-readable file sizes (K, M, G instead of raw bytes) ls -lh # List a specific directory without changing into it ls -l /etc/ssh
# Determine what kind of content a file actually contains
file /etc/passwd
file /usr/bin/bash
file /etc/ssh/ssh_host_ed25519_key
report.txt could actually contain binary data. Use file when you're not sure what you're looking at.
# Create a new empty directory mkdir project # Create nested directories in one step mkdir -p project/src/lib # Create an empty file, or update its timestamp if it exists touch notes.txt # Copy a file cp notes.txt notes-backup.txt # Copy a directory and its contents recursively cp -r project/ project-backup/ # Move or rename a file (mv does both) mv notes-backup.txt archive/notes-2026.txt # Remove a file rm notes.txt # Remove a directory and everything inside it rm -r project-backup/ # Prompt before each removal — a safer habit for destructive commands rm -ri project-backup/
rm -r on the wrong directory — especially combined with -f to force it — can destroy data permanently. Double-check the path before pressing Enter.
A link lets one or more names refer to the same underlying data. Linux supports two kinds.
| Type | Behavior |
|---|---|
| Hard link | A second directory entry pointing to the same inode; both names are equally "real." Cannot cross filesystems or point to directories. |
| Symbolic link (symlink) | A special file that stores a path to another file. Can cross filesystems and point to directories. Breaks if the target is removed. |
# Create a hard link ln original.txt hardlink.txt # Create a symbolic link ln -s /etc/ssh/sshd_config sshd_config_link # Symlinks are visually distinguishable in a long listing (-> target) ls -l sshd_config_link
# Find files by name under a starting directory find /etc -name "*.conf" # Case-insensitive name search find /home -iname "*report*" # Find only regular files, or only directories find /var/log -type f find /var/log -type d # Find files modified in the last 1 day find /etc -mtime -1 # Find files larger than 100 megabytes find / -size +100M
find searches the live filesystem in real time, so results are always current but the search can be slow on large trees. locate (if installed) searches a prebuilt index — much faster, but only as current as its last database update.
//cd .. and cd -?data.txt but suspect it isn't actually plain text. What command would confirm what it really is?mkdir lets you create a directory and any missing parent directories in one command?rm -r considered dangerous, and what option can make it safer to run interactively?find command that searches /var/log for regular files larger than 50 megabytes.