Linux Terminal Cheat Sheet

Essential Bash commands for file ops, navigation, search, processes, networking, and permissions

File Operations
File ls — list directory contents
ls # current directory
ls -la # all files with details
ls -lh # human-readable sizes
ls *.txt # pattern match
💡 -a shows hidden files. -l long format. -h with -l for readable sizes.
File cp — copy files/directories
cp file.txt dest/ # copy file
cp -r dir/ dest/ # recursive copy directory
cp -i file.txt bak/ # prompt before overwrite
💡 -r for directories. -v verbose. -i interactive (safe). -p preserve attributes.
File mv — move or rename
mv file.txt newname.txt # rename
mv file.txt /path/dir/ # move
mv -i *.txt backup/ # interactive bulk
💡 Overwrites by default. Use -i (interactive) or -n (no-clobber) to prevent.
File rm — remove files/directories
rm file.txt # remove file
rm -r dir/ # remove directory recursively
rm -rf dir/ # force, no prompts (DANGEROUS)
rm -i *.log # prompt before each removal
⚠️ rm -rf is irreversible. Triple-check path. Use trash-cli for safer deletion.

Directory Ops

mkdir — make directory
mkdir newdir
mkdir -p a/b/c # create nested
rmdir — remove empty dir
rmdir emptydir
rmdir -p a/b # remove parents if empty
File touch — create empty file or update timestamp
touch newfile.txt # create empty
touch file1 file2 file3 # multiple files
💡 Also used to update file timestamps without modifying content. -t option sets explicit timestamp.

View File Contents

cat — concatenate/print file
cat file.txt
cat f1 f2 > combined.txt
less — scrollable viewer (preferred)
less longfile.log
j/k scroll, q quit, /search
more — basic paginator
more file.txt
space next, Enter line
💡 Use less for large files. cat is best for small files or piping.
Navigation

Directory Navigation

pwd — print working dir
pwd
cd — change directory
cd /path/to/dir
cd .. # parent
cd ~ # home
cd - # previous dir
Search & Find
Search grep — search text in files
grep "pattern" file.txt
grep -r "TODO" . # recursive in current dir
grep -i "error" log.txt # case-insensitive
grep -n "fn" file.js # show line numbers
grep -v "debug" code.js # invert: exclude lines
💡 -r recursive. -i case-insensitive. -n line numbers. -v invert match (exclude).
Search find — search for files/dirs
find . -name "*.txt" # by name pattern
find /var/log -type f # only files
find . -size +10M # larger than 10 MB
find . -mtime -7 # modified in last 7 days
find . -exec rm {} \; # execute on each result
💡 -name (case-sensitive), -iname (case-insensitive). -exec runs command on matches. {} is placeholder.

Locate Binaries

which — path of executable
which node
which -a python # all matches
whereis — binary, source, man loc
whereis gcc
Process Management

View Processes

ps — snapshot of processes
ps aux # all processes
ps -ef | grep node # filter
top — live process viewer
top
q to quit, M sort by mem
htop — enhanced top
htop
(install: apt/brew)

Kill Processes

kill — send signal by PID
kill 1234 # SIGTERM
kill -9 1234 # SIGKILL (force)
pkill — by process name
pkill -f "node app.js"
killall — kill by exact name
killall chrome
⚠️ kill -9 (SIGKILL) does not allow graceful shutdown. Try kill (SIGTERM) first.
Process jobs / bg / fg — background tasks
command & # start in background
jobs # list background jobs
fg %1 # bring job 1 to foreground
bg %1 # resume job in background
💡 Use Ctrl+Z to suspend current foreground job, then bg or fg to resume.
Permissions
Perm chmod — change file permissions
chmod +x script.sh # add execute
chmod 755 app.js # rwxr-xr-x
chmod 644 config.json # rw-r--r--
chmod -R 755 dir/ # recursive
💡 Numeric: read=4, write=2, exec=1. Sum per class (user/group/others).
755 = rwx (7) r-x (5) r-x (5)
644 = rw- (6) r-- (4) r-- (4)
Perm chown — change file owner/group
chown alice file.txt # change owner
chown alice:staff file.txt # owner and group
chown -R www-data:www-data /var/www # recursive
⚠️ Requires sudo on most systems. Incorrect ownership can break services.
Networking

Download / HTTP

curl — transfer data (CLI browser)
curl -O https://url/file.zip
curl -I https://site.com # headers only
wget — download file
wget URL
wget -c file.zip # continue partial

Network Diagnostics

ping — test connectivity
ping google.com
ping -c 4 host # count=4
traceroute — path to host
traceroute google.com
nslookup — DNS lookup
nslookup example.com
Net ss / netstat — socket statistics
ss -tulpn # listening ports
netstat -tulpn # traditional (older)
💡 ss is modern replacement for netstat on Linux. -t TCP, -u UDP, -l listening, -p process.
System Info

Disk Usage

df — disk free (filesystem)
df -h # human-readable
df -i # inode usage
du — disk usage (directory)
du -sh dir/ # summary human-readable
du -h --max-depth=1 # per-subdir

Memory / System

free — memory usage
free -h
uname — system info
uname -a # all details
uname -r # kernel version
Compression & Archives
File tar — tape archive (bundles files)
tar -cvf archive.tar dir/ # create tar
tar -xvf archive.tar # extract
tar -czvf archive.tar.gz dir/ # create gzipped
tar -xzvf archive.tar.gz # extract gzipped
tar -tjvf archive.tar # list contents
💡 Flags: -c create, -x extract, -v verbose, -f file, -z gzip, -j bzip2.
Order doesn't matter: tar -zcvf = tar -czvf.

Compress Single Files

gzip — compress file
gzip file.txt
gunzip file.txt.gz
zip — zip archive
zip -r out.zip dir/
unzip — extract zip
unzip out.zip
💡 gzip compresses files in-place (replaces original with .gz). Use tar for directories.
Text Processing

Basic Text

echo — print to stdout
echo "text"
echo $PATH # variable
head — first N lines
head file.txt
head -n 20 # 20 lines
tail — last N lines
tail -f logfile # follow live
tail -n 50 # last 50 lines
Text wc — word/line/byte count
wc file.txt # lines words bytes
wc -l file.txt # line count only
wc -w file.txt # word count
ls -1 | wc -l # count files in dir

Sort & Unique

sort — sort lines
sort file.txt
sort -r # reverse
sort -n # numeric
uniq — remove duplicates
uniq sorted.txt
sort file | uniq -c # count per value
💡 uniq only removes adjacent duplicates. Pipe through sort first for full deduplication.

Stream Editors

sed — stream editor
sed 's/old/new/g' file.txt
sed -i 's/foo/bar/g' file # in-place
awk — pattern scanning
awk '{print $1}' file
awk -F: '{print $1}' /etc/passwd
💡 sed 's/old/new/' replaces first occurrence. g flag = global (all). -i edits file in-place.

About This Tool

The Linux Terminal Cheat Sheet is a quick reference for essential Bash and shell commands. It covers the most commonly used commands across file operations, navigation, process management, networking, permissions, and text processing. Each command includes brief explanations and copy-ready examples.

Command Syntax Quick Guide

  • Flags/options: Short (-la) or long (--all). Combine shorts: -la = -l -a.
  • Positional arguments: Usually file/directory paths that come after flags.
  • Wildcards: * (any chars), ? (single char), [...] (set).
  • Piping: cmd1 | cmd2 sends output of first as input to second.
  • Redirection: > out.txt (overwrite), >> out.txt (append), 2> err.txt (stderr).
  • Chaining: cmd1 && cmd2 runs second if first succeeds. cmd1; cmd2 runs regardless.

Frequently Asked Questions

How do I see hidden files?

Use ls -a to show all files including dotfiles (starting with .). For detailed view: ls -la.

What does chmod 755 mean?

755 sets permissions: user = rwx (7), group = r-x (5), others = r-x (5). Commonly used for scripts and public executables. Read=4, write=2, execute=1. Sum them per class.

How do I kill a process safely?

First try kill PID (SIGTERM — graceful shutdown). If it doesn't respond, use kill -9 PID (SIGKILL — forced, no cleanup). Find PID with ps aux | grep name or pgrep name.

What's the difference between tar -czf and tar -cJf?

-z uses gzip (fast, moderate compression). -J uses xz (slower, higher compression). -j uses bzip2 (middle ground).

Is this tool free?

Yes, completely free with no sign-up required.

Related Tools