Navigating and managing files: the Linux file system, paths, ls, cd, mkdir, cp, mv, rm, find and wildcards
Everything on a Linux system lives in one big tree of folders (called directories), starting at /. Before you can manage a web server, edit configs or write scripts, you need to move around this tree confidently and create, copy, move and delete files without a mouse. This unit covers the file system layout and every essential file command, with the mistakes to avoid.
The directory tree
/
├── bin, usr/bin programs (ls, cp, python3...)
├── etc system configuration files (nginx, ssh, users)
├── home users' personal folders (/home/wanjiku)
├── root the root user's home
├── var changing data: logs (/var/log), websites (/var/www), databases
├── tmp temporary files (cleared on reboot)
├── opt optional/third-party software
├── dev devices (disks, terminals)
├── proc, sys live kernel and process information
├── mnt, media mounted drives and USB sticks
└── boot the kernel and boot loaderUnlike Windows, there are no drive letters (C:, D:). Extra disks and USB drives are mounted into the tree, e.g. /media/wanjiku/USB.
Paths
| Path type | Example | Meaning |
|---|---|---|
| Absolute | /home/wanjiku/projects/site | Starts from /; works from anywhere |
| Relative | projects/site | Starts from where you are now |
~ | ~/projects | Your home folder (/home/wanjiku) |
. | ./script.sh | The current folder |
.. | ../images | The parent folder (one level up) |
Listing: ls
ls # names in the current folder
ls -l # long format: permissions, owner, size, date
ls -a # include hidden files (names starting with .)
ls -lh # human-readable sizes (K, M, G)
ls -lt # newest first
ls -R # include sub-folders
ls /var/log # list another folderReading ls -l:
-rw-r--r-- 1 wanjiku wanjiku 2048 Sep 7 10:15 index.html
drwxr-xr-x 2 wanjiku wanjiku 4096 Sep 7 10:16 images| Part | Meaning |
|---|---|
- / d / l | Regular file / directory / symbolic link |
rw-r--r-- | Permissions (owner, group, others): next lessons |
wanjiku wanjiku | Owner and group |
2048 | Size in bytes |
Sep 7 10:15 | Last modified |
Moving around: cd
cd /var/log # absolute path
cd projects # relative path
cd .. # up one level
cd ../.. # up two levels
cd ~ (or just cd) # home
cd - # back to the previous folderUse Tab to complete folder names. Names with spaces need quotes or a backslash: cd "My Documents" or cd My\ Documents. Better yet, avoid spaces in names; use my-documents.
Creating files and folders
mkdir website # one folder
mkdir -p website/css website/js # -p creates parents and doesn't complain if they exist
touch website/index.html # create an empty file (or update its timestamp)
echo "Hello" > notes.txt # create a file with contentCopying: cp
cp index.html index-backup.html # copy a file
cp index.html website/ # copy into a folder
cp -r website website-backup # copy a folder (-r = recursive)
cp -i a.txt b.txt # ask before overwriting
cp -v *.jpg images/ # verbose: show each file copiedMoving and renaming: mv
mv old-name.html new-name.html # rename
mv report.pdf ~/Documents/ # move
mv *.png images/ # move many files
mv -i a.txt folder/ # ask before overwritingThere's no separate rename command for single files: renaming is moving to a new name.
Deleting: rm and rmdir
rm file.txt # delete a file
rm -i *.log # ask for each file
rmdir empty-folder # delete an empty folder
rm -r old-site # delete a folder and everything insideWildcards (globbing)
| Pattern | Matches |
|---|---|
* | Any characters: *.jpg = all JPG files |
? | Exactly one character: file?.txt = file1.txt, fileA.txt |
[abc] | One of these: [0-9]*.csv starts with a digit |
{a,b} | Each alternative (brace expansion): mkdir {css,js,img} |
ls *.html
cp report-2026-0?.pdf archive/
mkdir -p project/{src,docs,tests}
rm -i *.tmpFinding files
find ~ -name "*.pdf" # by name under home
find /var/www -type f -name "*.php" # files only
find . -type d -name "node_modules" # folders
find /var/log -mtime -1 # modified in the last day
find . -size +100M # larger than 100 MB
find . -name "*.tmp" -delete # find and delete (check without -delete first!)locate is faster (it searches a database updated daily): sudo apt install plocate, then locate nginx.conf.
Hidden files, types and links
- Files starting with
.are hidden:.bashrc(shell settings),.ssh/(keys),.git/,.env. file photo.jpgtells you what a file really is, regardless of its extension.- A symbolic link is a shortcut:
ln -s /var/www/site/current ~/sitecreates~/sitepointing to the real folder.
Disk usage quick checks
du -sh website/ # size of a folder
du -sh * | sort -h # sizes of everything here, smallest to largest
df -h # free space on each diskPractice task
- In your home folder, create
practice/{docs,images,backup}in one command. - Create
docs/notes.txtanddocs/todo.txt. - Copy all
.txtfiles tobackup/. - Rename
docs/todo.txttodocs/tasks.txt. - Use
findto list every.txtfile underpractice. - Delete the
backupfolder (check withlsfirst).
Think about it: You're in /home/wanjiku/projects/site/css. Write two different commands to go to /home/wanjiku/projects/site/images.Show answer
Relative: cd ../images. Absolute: cd /home/wanjiku/projects/site/images (or cd ~/projects/site/images).
Summary
- Linux has one directory tree from
/:/etcconfigs,/homeusers,/var/loglogs,/var/wwwwebsites. - Absolute paths start with
/; relative paths start from the current folder;~,.,..are shortcuts. ls -lah,cd,mkdir -p,touch,cp -r,mv,rm -rmanage files;rmis permanent.- Wildcards (
*,?,[ ],{ }) act on many files; preview withlsfirst. findsearches by name, type, size and age;duanddfcheck space.
Check yourself
Which folder holds most system configuration files?
Show answer
/etc
Which symbol means the parent folder?
Show answer
..
Which option makes cp copy a whole folder?
Show answer
-r
Which mkdir option creates parent folders as needed?
Show answer
-p
Which wildcard matches exactly one character?
Show answer
?
Does rm move files to a Recycle Bin? (yes/no)
Show answer
no