Everything in Linux is a file. Directories are files, hardware devices are files, and even running processes are represented as files. Understanding the file system is fundamental to working with Linux.
The Directory Tree
Linux uses a single directory tree starting from the root directory /. Unlike Windows, there are no drive letters — everything branches from /.
/
├── bin/ # Essential user binaries (ls, cp, mv)
├── etc/ # System configuration files
├── home/ # User home directories
│ └── sabaoon/
├── var/ # Variable data (logs, databases)
│ └── log/
├── tmp/ # Temporary files (cleared on reboot)
├── usr/ # User programs and libraries
│ ├── bin/
│ └── lib/
├── opt/ # Optional/third-party software
├── dev/ # Device files
├── proc/ # Process information (virtual filesystem)
└── root/ # Root user's home directory
Absolute vs Relative Paths
An absolute path starts from the root directory and always begins with /:
cd /home/sabaoon/projectsA relative path starts from your current directory:
# If you are in /home/sabaoon
cd projects
# Go up two directories
cd ../../var/logSpecial path references:
| Symbol | Meaning |
|---|---|
/ | Root directory |
~ | Your home directory |
. | Current directory |
.. | Parent directory |
- | Previous directory |
Creating Files and Directories
# Create an empty file
touch notes.txt
# Create a file with content
echo "Hello World" > greeting.txt
# Create a directory
mkdir projects
# Create nested directories (parents included)
mkdir -p projects/webapp/src
# Create multiple directories at once
mkdir css js imagesViewing File Contents
Linux provides several commands for reading files:
# Display entire file
cat readme.txt
# Display with line numbers
cat -n readme.txt
# View long files one page at a time
less server.log
# Press Space for next page, b for previous, q to quit
# Show first 10 lines
head server.log
# Show first 20 lines
head -n 20 server.log
# Show last 10 lines
tail server.log
# Follow a file in real time (great for logs)
tail -f /var/log/syslogCopying Files and Directories
# Copy a file
cp original.txt backup.txt
# Copy a file to another directory
cp report.pdf /home/sabaoon/documents/
# Copy a directory and all its contents
cp -r projects/ projects-backup/
# Copy with confirmation before overwriting
cp -i original.txt backup.txt
# Preserve file attributes (permissions, timestamps)
cp -p original.txt backup.txtMoving and Renaming
The mv command handles both moving and renaming:
# Rename a file
mv oldname.txt newname.txt
# Move a file to another directory
mv report.pdf ~/documents/
# Move a directory
mv projects/ /opt/projects/
# Move with confirmation before overwriting
mv -i source.txt destination.txt
# Move multiple files to a directory
mv *.txt ~/documents/Deleting Files and Directories
# Delete a file
rm unwanted.txt
# Delete with confirmation
rm -i important.txt
# Delete an empty directory
rmdir empty-folder/
# Delete a directory and all its contents
rm -r old-project/
# Force delete without confirmation (use with caution)
rm -rf temp-files/Warning: rm -rf is permanent. There is no recycle bin in the terminal. Always double-check your path before running destructive commands.
Finding Files
# Find files by name
find /home -name "*.txt"
# Find files by name (case-insensitive)
find /home -iname "readme*"
# Find directories only
find /var -type d -name "log"
# Find files larger than 100MB
find / -size +100M
# Find files modified in the last 7 days
find /home -mtime -7
# Find and execute a command on results
find . -name "*.tmp" -exec rm {} \;The locate command is faster than find because it searches a pre-built database:
# Search the file database
locate nginx.conf
# Update the database (run as root)
sudo updatedbWildcards and Globbing
Wildcards let you match multiple files at once:
| Pattern | Matches |
|---|---|
* | Any number of characters |
? | Exactly one character |
[abc] | Any one of the characters a, b, or c |
[0-9] | Any digit |
{txt,md} | Either "txt" or "md" |
# List all .js files
ls *.js
# List files starting with "test" and ending with any extension
ls test*.*
# List files with single-character names
ls ?.txt
# Copy all images
cp *.{jpg,png,gif} ~/images/Disk Usage
# Show disk space usage for all mounted filesystems
df -h
# Show directory size
du -sh ~/projects/
# Show sizes of subdirectories
du -h --max-depth=1 ~/projects/
# Find the largest files in a directory
du -ah ~/projects/ | sort -rh | head -10Links
Linux supports two types of links:
# Create a symbolic link (shortcut)
ln -s /var/log/syslog ~/syslog-link
# Create a hard link (same data, different name)
ln original.txt hardlink.txt
# Check where a symbolic link points
readlink -f ~/syslog-linkSymbolic links are like shortcuts — they point to a path. Hard links point to the same data on disk, so deleting the original file does not affect the hard link.
Summary
You now understand the Linux directory tree, how to navigate with absolute and relative paths, and how to create, copy, move, delete, and find files. These operations form the backbone of everything you will do in the terminal. Next, you will learn about file permissions and user management.