// CyberGrind · Orange Book · OS Infographic Series — 08 of 09

Linux Terminal Commands

Essential bash commands for file management, system administration, networking, permissions, and scripting.

bash 5.x — Ubuntu 24.04 LTS
# Case-sensitive! ls ≠ LS. Pipe | chains commands. && runs next only if previous succeeds
logan@ubuntu:~$ ls -lah /var/log | grep "\.log" | sort -k5 -rh | head -5
-rw-r--r-- 1 root adm 42M Apr 28 syslog
-rw-r----- 1 syslog adm 18M Apr 28 auth.log
Critical: Linux is always case-sensitive — commands, filenames, and paths. ls works; LS → "command not found". This is the most common source of confusion when switching from Windows or macOS.
// Navigation & File Operations
ls -lah --color=auto
-l=long -a=all hidden -h=human sizes
List directory. -a shows dot files, -S sort by size, -t sort by time. --sort=extension for ext grouping.
cd /etc | cd .. | cd ~ | cd -
absolute · parent · home · previous
Change directory. cd - returns to previous directory. cd ~user goes to that user's home.
cp -rv /src /dst
-r=recursive -v=verbose
Copy files/dirs. -p preserves timestamps and permissions. -u only copies if source is newer.
rm -rf /path/to/dir
⚠ PERMANENT — no Recycle Bin
Delete permanently. -r for dirs, -f skips confirmation. No undo. Never run rm -rf / as root.
cat f | less f | head -20 | tail -f
print · page · top N · live follow
View file content. less: q=quit /=search space=next page. tail -f follows live log writes.
mkdir -p parent/child/sub
-p creates full path tree
Create directory. -p creates all parent directories — no error if already exists.
// Search & Text Processing
grep -rni "pattern" /path/
-r=recurse -n=line# -i=case insensitive
Search text. -l for filenames only. -c for count. --include="*.log" to scope. -E for extended regex.
find /etc -name "*.conf" -type f
-name -type -mtime -size -user -perm
Find files. -mtime -1 for last day. -size +100M for large files. -exec rm {} \; to act on results.
sed -i 's/old/new/g' file.txt
stream editor — in-place replace
Replace text in files. /g = all occurrences. Without -i, outputs to stdout. -E for extended regex.
awk '{print $1, $3}' file.txt
$0=line $1=first field $NF=last
Extract columns. -F: sets field separator. Powerful for parsing logs, CSVs, /etc/passwd.
sort -k2 -rn | uniq -c
-k=key -r=reverse -n=numeric
Sort lines. uniq -c counts duplicates. Classic combo: sort | uniq -c | sort -rn for frequency.
wc -l file | cut -d: -f1 /etc/passwd
count · field extract
wc counts lines/words/bytes. cut extracts specific fields from delimited text. Essential for log parsing.
// Process & System Management
ps aux | grep nginx
a=all users u=format x=no-tty
List processes. Pipe to grep to filter. top/htop/btop for interactive live monitoring.
kill -9 PID | killall nginx
-9=SIGKILL (force) -15=SIGTERM
SIGTERM (15) requests graceful shutdown; SIGKILL (9) forces immediate termination.
systemctl status/start/stop nginx
systemd service control
Manage systemd services. enable/disable controls auto-start. journalctl -u nginx -f for logs.
df -h | du -sh /var/log/*
disk free · disk usage
df shows filesystem usage. du shows directory sizes. -h for human-readable MB/GB output.
ss -tlnp
replaces netstat — faster
Show listening sockets. -t=TCP -l=listening -n=numeric -p=process. Filter: ss -anp | grep :80
ssh user@host -p 22 -i ~/.ssh/key
-p=port -i=identity file
Secure shell. -L 8080:localhost:80 for port forward. -N for tunnel only. scp for file transfers.
// Linux Permissions — Read, Set, Understand
- rwx r-x r-- root staff 4096 script.sh
Type: - file | d dir | l symlink
Owner: rwx = 7 (read+write+exec)
Group: r-x = 5 (read+exec)
Other: r-- = 4 (read only)
Symbolic
chmod u+x script.sh
chmod a+r public.html
u=user g=group o=other a=all
Octal
chmod 755 script.sh # rwxr-xr-x
chmod 644 config.txt # rw-r--r--
chmod 600 id_rsa # rw-------
// Power Patterns — Pipes & Chaining
grep -i "fail" /var/log/auth.log | awk '{print $NF}' | sort | uniq -c | sort -rn | head
Top failed login IPs
find / -perm -4000 -type f 2>/dev/null
Find all SUID files (security audit)
cat /etc/passwd | cut -d: -f1 | sort | uniq
List all unique usernames
ps aux | awk '{sum+=$3} END {print "Total CPU%:", sum}'
Sum CPU across all processes