Linux Filesystem Tree Structure
/
├── bin/ Essential user command binaries
├── boot/ Boot loader files, kernels
├── dev/ Device files
├── etc/ System configuration files
├── home/ User home directories
├── lib/ Essential shared libraries
├── media/ Mount points for removable media
├── mnt/ Temporary mount points
├── opt/ Optional software packages
├── proc/ Virtual filesystem for process info
├── root/ Home directory for root user
├── run/ Runtime variable data
├── sbin/ System administration binaries
├── srv/ Data for services
├── sys/ Virtual filesystem for kernel objects
├── tmp/ Temporary files
├── usr/ User utilities and applications
└── var/ Variable data files (logs, spool, cache)
└── log/ System log files
🎯 Learning Objectives
- Understand the Linux filesystem hierarchy[cite: 38].
- Navigate efficiently using absolute and relative paths[cite: 38].
- Learn the purpose of important system directories[cite: 38].
- Master the
pwdandcdcommands[cite: 38]. - Build confidence before learning file management commands[cite: 38].
📋 Prerequisites
You should have completed Chapter 1[cite: 38]. No prior Linux experience is required beyond understanding what Linux is and how to access a terminal[cite: 38].
1. Introduction
Every Linux administrator spends a significant amount of time navigating the filesystem[cite: 38]. Configuration files, application data, log files, software packages and user documents are all stored within a single, well-defined directory hierarchy[cite: 38]. Understanding this structure is one of the most valuable skills for beginners because nearly every command you learn later depends on knowing where files are located[cite: 38].
2. Understanding the Linux Filesystem
Unlike Windows, Linux does not organize storage using drive letters such as C: or D:[cite: 38]. Instead, everything begins from a single top-level directory called the root directory (/)[cite: 38]. Additional disks, USB devices and network filesystems are attached somewhere under this hierarchy through a process called mounting[cite: 38].
/
├── boot
├── dev
├── etc
├── home
├── opt
├── proc
├── root
├── tmp
├── usr
└── var
3. Important Linux Directories
| Directory | Purpose | Production Example |
|---|---|---|
| /etc | Configuration files | sshd_config, fstab[cite: 38] |
| /var | Logs & variable data | /var/log[cite: 38] |
| /home | User home directories | /home/admin[cite: 38] |
| /root | Root user's home | /root[cite: 38] |
| /usr | Applications & libraries | /usr/bin[cite: 38] |
| /opt | Optional software | Oracle, IBM tools[cite: 38] |
| /tmp | Temporary files | Installer files[cite: 38] |
| /boot | Kernel & bootloader | vmlinuz[cite: 38] |
| /dev | Device files | /dev/sda[cite: 38] |
| /proc | Kernel information | /proc/cpuinfo[cite: 38] |
| /sys | Hardware interface | /sys/class[cite: 38] |
4. Absolute vs Relative Paths
An absolute path always starts from /, while a relative path starts from your current working directory[cite: 38].
Absolute: /home/student/Documents/report.txt
Relative: Documents/report.txt
| Type | Starts With | Depends on Current Location? |
|---|---|---|
| Absolute | /[cite: 38] | No[cite: 38] |
| Relative | Directory name[cite: 38] | Yes[cite: 38] |
5. The pwd Command
The pwd command prints the current working directory[cite: 38].
$ pwd
/home/student
6. The cd Command
The cd command changes your current directory[cite: 38].
| Command | Description |
|---|---|
| cd | Go to home directory[cite: 38] |
| cd / | Go to root[cite: 38] |
| cd .. | Move one level up[cite: 38] |
| cd - | Return to previous directory[cite: 38] |
| cd ~ | User home directory[cite: 38] |
7. Hands-on Practice
- Navigate to
/var[cite: 38]. - Return to your home directory[cite: 38].
- Move to the root directory[cite: 38].
- Use
cd -to return[cite: 38]. - Verify every step using
pwd[cite: 38].
8. Listing Files with ls
The ls command displays the contents of a directory[cite: 38]. It is one of the first commands administrators use after logging in[cite: 38].
| Option | Description |
|---|---|
| -l | Long listing format[cite: 38]. |
| -a | Show hidden files[cite: 38]. |
| -h | Human-readable sizes[cite: 38]. |
| -t | Sort by modification time[cite: 38]. |
| -R | Recursive listing[cite: 38]. |
9. Creating Directories with mkdir
mkdir project
mkdir logs backup temp
mkdir -p /tmp/demo/test
The -p option creates parent directories automatically if they do not already exist[cite: 38].
10. Creating Files with touch
touch notes.txt
touch file1 file2 file3
touch /tmp/app.log
Besides creating empty files, touch also updates file timestamps[cite: 38].
11. Copying Files with cp
cp file1 file2
cp report.txt /backup/
cp -r project backup_project
| Option | Purpose |
|---|---|
| -r | Copy directories recursively[cite: 38]. |
| -i | Prompt before overwrite[cite: 38]. |
| -v | Show copied files[cite: 38]. |
12. Moving and Renaming Files with mv
mv old.txt new.txt
mv report.txt /archive/
mv *.log /var/log/archive/
The same command is used both for renaming files and moving them to a different directory[cite: 38].
13. Removing Files with rm
rm file.txt
rm -i file.txt
rm -r directory
rm -rf temp_directory
14. Viewing Files with cat, less, and tail
cat displays the contents of text files natively[cite: 38]. Large log files should be viewed with less because it loads data page by page[cite: 38].
| Command | Purpose |
|---|---|
| head | First 10 lines by default[cite: 38]. |
| tail | Last 10 lines by default[cite: 38]. |
| tail -f | Monitor a growing log file in real time[cite: 38]. |
15. Searching via find and locate
The find command searches directories based on name, type, size, and modifications[cite: 38].
find /etc -name sshd_config
find . -name "*.log"
16. Hard Links vs Symbolic Links
| Feature | Hard Link | Symbolic Link |
|---|---|---|
| Shares inode | Yes[cite: 38] | No[cite: 38] |
| Cross filesystem | No[cite: 38] | Yes[cite: 38] |
| Can link directories | No[cite: 38] | Yes[cite: 38] |
| Breaks if source removed | No[cite: 38] | Yes[cite: 38] |
17. Inspecting Files with stat and file
The stat command displays detailed metadata including permissions, inode, timestamps and ownership[cite: 38]. The file command determines the actual file type instead of relying on the filename extension[cite: 38].
18. Disk Usage Commands (df, du)
Use df -h to check free and used space on mounted filesystems[cite: 38]. Use du -sh to determine which directories consume the most storage footprint[cite: 38].
Commands Covered in This Chapter
pwd- Print working directory[cite: 38]cd- Change directory[cite: 38]ls- List directory contents[cite: 38]touch- Create empty file or update timestamp[cite: 38]mkdir- Create directories[cite: 38]cp- Copy files and directories[cite: 38]mv- Move/rename files and directories[cite: 38]rm- Remove files and directories[cite: 38]cat- Concatenate and display files[cite: 38]less- View file contents page by page[cite: 38]head- Display first lines of file[cite: 38]tail- Display last lines of file[cite: 38]find- Search for files in directory hierarchy[cite: 38]ln- Create hard and symbolic links[cite: 38]du- Estimate file space usage[cite: 38]df- Report filesystem disk space usage[cite: 38]
Real Production Scenario: Locating Log Files
Scenario: Your web application is throwing 500 errors. You need to find recent error logs[cite: 38].
cd /var/log
ls -lht | grep error
tail -n 50 /var/log/apache2/error.log
find /var/log -type f -mtime -1 -name "*.log"
This workflow is used daily by production SREs and sysadmins to troubleshoot live issues[cite: 38].