FreeSheet 02 of 7
Next in LinuxNetworking
File Navigation & Manipulation
A comprehensive developer cheatsheet covering Linux file navigation and manipulation, featuring essential CLI commands, common flags, and operational workflows for directory traversal (cd, ls, pwd), file creation and viewing (touch, cat, less, tail), copy/move/delete operations (cp, mv, rm), symbolic linking (ln), metadata inspection (stat, file), and critical system safety practices.
Navigation Commands
pwd — Print Working Directory
Flags: -P (physical), -L (logical)
bash
$ pwd
/home/bob/projects/linux-training
Prints the absolute path of the current working directory.
ls — List Directory Contents
Flags: -l (long), -a (all hidden), -R (recursive), -t (sort by time), -S (sort by size), -h (human-readable), -i (show inode)
bash
$ ls -lah
total 48K
drwxr-xr-x 5 bob staff 160 Jan 15 10:30 .
drwxr-xr-x 12 bob staff 384 Jan 15 09:00 ..
-rw-r--r-- 1 bob staff 12K Jan 15 10:25 report.pdf
-rwxr-xr-x 1 bob staff 24K Jan 14 16:40 script.sh
drwxr-xr-x 2 bob staff 64 Jan 15 08:00 backup/
Lists directory contents with permissions, ownership, size, and timestamps.
cd — Change Directory
Flags: ~ (home), - (previous), .. (parent), ../.. (two levels up)
bash
$ cd ~/projects
(No output — directory changed silently)
Changes the current directory. cd - goes back to the previous directory.
mkdir — Make Directory
Flags: -p (create parents), -v (verbose), -m (set permissions)
bash
$ mkdir -pv project/{src,bin,docs}
mkdir: created directory 'project'
mkdir: created directory 'project/src'
mkdir: created directory 'project/bin'
mkdir: created directory 'project/docs'
Creates directories. -p creates parent directories if they don't exist.
File Creation & Viewing
touch — Create File or Update Timestamp
Flags: -a (access time), -m (modify time), -c (no create), -t (set timestamp)
bash
$ touch newfile.txt && ls -l newfile.txt
-rw-r--r-- 1 bob staff 0 Jan 15 10:35 newfile.txt
Creates an empty file or updates the timestamp of an existing file.
cat — Concatenate and Print Files
Flags: -n (number lines), -b (number non-empty), -s (squeeze blanks), -E (show $ at ends)
bash
$ cat -n config.txt
1 server {
2 listen 80;
3 server_name example.com;
4 }
Concatenates and prints the entire file to stdout. -n adds line numbers.
less — Page-by-Page File Viewer
Flags: -N (line numbers), -S (chop long lines), -g (highlight search), -i (ignore case)
bash
$ less -N longfile.log
[Interactive — first page shown, press Space to scroll, / to search, q to quit]
Page-by-page file viewer. Navigate with Space (down), B (up), / (search), q (quit).
head — Print First Lines
Flags: -n (lines), -c (bytes), -q (quiet)
bash
$ head -n 3 data.csv
Name,Age,City
Alice,30,New York
Bob,25,London
Prints the first N lines (default: 10) of a file.
tail — Print Last Lines (and Follow Logs)
Flags: -n (lines), -f (follow), -F (follow with rotation), -c (bytes), --pid (stop if PID dies)
bash
$ tail -f /var/log/syslog
Jan 15 10:40:12 server systemd[1]: Started Session 42.
Jan 15 10:40:15 server sshd[1234]: Accepted publickey for bob from 192.168.1.100
Jan 15 10:40:20 server cron[5678]: (root) CMD (run-parts /etc/cron.hourly)
^C (Press Ctrl+C to stop following)
Prints the last N lines (default: 10). -f follows live log output — essential for monitoring.
more — Older Pager (Use less Instead)
Flags: -d (prompt), -c (clear screen)
bash
$ more file.txt
[Older pager — use 'less' instead as it's more feature-rich]
Older pager for viewing files. less is more advanced and recommended.
Copy, Move & Delete Operations
cp — Copy Files or Directories
Flags: -r (recursive), -p (preserve attributes), -u (update), -i (interactive), -l (hard link), -s (symlink), -b (backup)
bash
$ cp -rp source_folder/ backup_folder/
(No output on success — check with ls -l)
Copies files or directories. -r for folders, -p preserves permissions/timestamps.
Interactive Example:
bash
$ cp -i important.txt /backup/
cp: overwrite '/backup/important.txt'? y
-i prompts before overwriting — prevents accidental data loss.
mv — Move or Rename Files
Flags: -i (interactive), -u (update), -b (backup), -f (force)
bash
$ mv old_report.pdf Q1_2026_report.pdf
(No output — file renamed silently)
Moves OR renames files/directories. Same command for both operations.
Interactive Example:
bash
$ mv -i file.txt /tmp/
mv: overwrite '/tmp/file.txt'? n
-i prompts before overwriting at the destination.
rm — Remove/Delete Files or Directories
Flags: -r (recursive), -f (force), -i (interactive), -d (remove empty dirs), -v (verbose)
Safe Deletion:
bash
$ rm -i oldfile.txt
rm: remove regular file 'oldfile.txt'? y
Deletes files. -i prompts for confirmation. Never use rm -rf / — it deletes your entire system!
DANGEROUS — Use with Extreme Caution:
bash
$ rm -rf temp_folder/
(No output — folder and all contents deleted instantly)
-rf forces deletion without any prompts. Triple-check before running!
rmdir — Remove Empty Directories
Flags: -p (remove parents), --ignore (suppress errors)
bash
$ rmdir emptydir
(No output — empty directory removed)
Removes ONLY empty directories. Safer than rm -r because it won't delete files.
Error Example:
bash
$ rmdir nonempty_folder/
rmdir: failed to remove 'nonempty_folder/': Directory not empty
Will fail with an error if the directory contains files — use rm -r instead.
ln — Create Links
Flags: -s (symbolic link), -f (force), -n (no dereference), -i (interactive)
bash
$ ln -s /usr/bin/python3 /usr/bin/python
(No output — symlink created)
Creates a symbolic link (shortcut). -s makes it a symlink. Without -s, it creates a hard link.
Verify the Link:
bash
$ ls -l /usr/bin/python
lrwxrwxrwx 1 root root 16 Jan 15 10:45 /usr/bin/python -> /usr/bin/python3
The l at the start indicates it's a symlink, and the -> shows where it points.
File Information & Metadata
stat — Display Detailed File Status
Flags: -c (custom format), --printf (formatted output)
bash
$ stat report.pdf
File: report.pdf
Size: 12345 Blocks: 24 IO Block: 4096 regular file
Device: 802h/2050d Inode: 987654 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 1001/ bob) Gid: ( 1001/ staff)
Access: 2026-01-15 10:30:22.123456789 +0000
Modify: 2026-01-15 09:15:00.987654321 +0000
Change: 2026-01-15 10:30:22.123456789 +0000
Birth: 2026-01-14 16:40:00.000000000 +0000
Displays detailed file system status: size, inode number, permissions, UID/GID, and all timestamps (Access, Modify, Change, Birth).
file — Determine File Type
Flags: -b (brief), -i (MIME type), -z (peek into compressed)
bash
$ file mysterious.dat
mysterious.dat: ASCII text, with very long lines (12345)
Determines the actual file type by examining content, not just the extension. Great for unknown files.
MIME Type Example:
bash
$ file -i image.png
image.png: image/png; charset=binary
-i outputs the MIME type — useful for web applications and scripting.
Quick Reference — Most Used Commands
Command Description
ls -la List all files including hidden
cd ~ Go to home directory
cp -r src/ dest/ Copy a folder recursively
mv old new Rename or move a file
rm -i file Delete with confirmation prompt
tail -f logfile Watch live log output
mkdir -p a/b/c Create nested directories
less -N file View file with line numbers
pwd Show current directory path
touch file.txt Create an empty file
The Nuclear Commands — DO NOT TYPE
These commands will permanently destroy your system or crash it instantly. No confirmation. No recycle bin. No undo. Ever.
Command What it does
rm -rf / Deletes your ENTIRE hard drive
rm -rf /* Same as above — deletes everything
dd if=/dev/zero of=/dev/sda Wipes the master boot record and filesystem
chmod -R 000 / Removes ALL permissions from the entire system
mv ~ /dev/null Moves your entire home directory into a black hole
:(){ :|:& };: Fork Bomb — crashes your system by spawning infinite processes
Shortcut Action
Tab Auto-complete file names and commands
Ctrl+C Cancel/kill the current running command
Ctrl+D Log out of the current terminal or exit a shell
Ctrl+Z Suspend the current command (put it in the background)
!! Re-run the last command (e.g., sudo !! re-runs with sudo)
Ctrl+R Reverse search through command history
Additional Tips
The Man Pages: If you forget how a command works, type man command (e.g., man ls). Press q to exit the manual.
Aliases: Save typing by creating shortcuts. Type alias ll='ls -la' to make ll show all files. Add this to ~/.bashrc to make it permanent.
The Shell is Case-Sensitive: File.txt and file.txt are completely different files.
Wildcards: Use * (any characters) and ? (single character) for pattern matching. Example: rm *.tmp removes all .tmp files.