Cheatsheet Linux Bash Shell Terminal Ubuntu Command Line Developer Tools 9 min read
Linux & Bash Cheat Sheet: Commands Every Dev Needs
By Vishnu Damwala
Quick reference tables
Navigation
Command
What it does
pwd
Print current directory
ls
List files
ls -la
List all files with details (including hidden)
ls -lh
Human-readable file sizes
cd /path
Change to absolute path
cd ~
Go to home directory
cd -
Go to previous directory
cd ..
Go up one level
tree
Show directory tree
tree -L 2
Tree limited to 2 levels deep
File operations
Command
What it does
touch file.txt
Create an empty file
mkdir dir
Create a directory
mkdir -p a/b/c
Create nested directories
cp file dest
Copy file
cp -r dir dest
Copy directory recursively
mv file dest
Move or rename file
rm file
Remove a file
rm -r dir
Remove directory recursively
rm -rf dir
Force remove (no prompts — careful!)
ln -s target link
Create a symbolic link
Reading files
Command
What it does
cat file
Print entire file
less file
Scroll through file (q to quit)
head file
First 10 lines
head -n 20 file
First 20 lines
tail file
Last 10 lines
tail -n 20 file
Last 20 lines
tail -f file
Follow file in real time (logs)
wc -l file
Count lines
wc -w file
Count words
Searching — grep & find
Command
What it does
grep "pattern" file
Search for pattern in file
grep -r "pattern" dir
Search recursively in directory
grep -i "pattern" file
Case-insensitive search
grep -n "pattern" file
Show line numbers
grep -v "pattern" file
Invert — lines that don’t match
grep -l "pattern" dir/*
List files containing pattern
find . -name "*.js"
Find files by name pattern
find . -type f -name "*.log"
Find files only (not dirs)
find . -type d -name "node_modules"
Find directories by name
find . -mtime -7
Files modified in last 7 days
find . -size +10M
Files larger than 10MB
Permissions
Command
What it does
ls -l
Show permissions in listing
chmod 755 file
Set permissions (rwxr-xr-x)
chmod +x file
Make file executable
chmod -R 755 dir
Set permissions recursively
chown user file
Change file owner
chown user:group file
Change owner and group
chown -R user:group dir
Change ownership recursively
sudo command
Run as superuser
su - user
Switch to another user
Permission numbers:
Number
Permissions
7
rwx (read + write + execute)
6
rw- (read + write)
5
r-x (read + execute)
4
r— (read only)
0
--- (no permissions)
Processes
Command
What it does
ps aux
List all running processes
ps aux | grep node
Find a specific process
top
Live process monitor
htop
Better live process monitor
kill PID
Kill a process by ID
kill -9 PID
Force kill
killall node
Kill all processes named node
pkill -f "pattern"
Kill processes matching pattern
bg
Resume stopped job in background
fg
Bring background job to foreground
jobs
List background jobs
nohup cmd &
Run command immune to hangup
Disk & memory
Command
What it does
df -h
Disk space usage (human-readable)
du -sh dir
Size of a directory
du -sh *
Size of each item in current dir
free -h
RAM usage
lsblk
List block devices (disks)
Networking
Command
What it does
ip a
Show IP addresses
ip r
Show routing table
ping host
Ping a host
curl url
Fetch a URL
curl -I url
Show HTTP headers only
curl -o file url
Download to a file
wget url
Download a file
ss -tulnp
Show listening ports
netstat -tulnp
Show listening ports (older)
ssh user@host
SSH into a remote machine
scp file user@host:/path
Copy file to remote
rsync -avz src/ dest/
Sync directories
Archives & compression
Command
What it does
tar -czf archive.tar.gz dir/
Create gzipped tar archive
tar -xzf archive.tar.gz
Extract gzipped tar
tar -tzf archive.tar.gz
List contents without extracting
zip -r archive.zip dir/
Create zip archive
unzip archive.zip
Extract zip
gzip file
Compress a file (replaces original)
gunzip file.gz
Decompress
Pipes, redirects & shortcuts
Symbol
What it does
cmd1 | cmd2
Pipe output of cmd1 to cmd2
> file
Redirect stdout to file (overwrite)
>> file
Redirect stdout to file (append)
2> file
Redirect stderr to file
2>&1
Redirect stderr to stdout
&> file
Redirect both stdout and stderr
/dev/null
Discard output
< file
Read stdin from file
cmd &
Run command in background
Shell keyboard shortcuts
Shortcut
What it does
Ctrl+C
Kill current process
Ctrl+Z
Suspend current process
Ctrl+D
Exit shell / EOF
Ctrl+L
Clear screen
Ctrl+A
Jump to start of line
Ctrl+E
Jump to end of line
Ctrl+U
Delete from cursor to start of line
Ctrl+K
Delete from cursor to end of line
Ctrl+W
Delete word before cursor
Ctrl+R
Search command history
↑ / ↓
Navigate command history
!!
Repeat last command
!$
Last argument of previous command
!cmd
Run most recent command starting with cmd
Variables & environment
Command
What it does
VAR=value
Set a local variable
export VAR=value
Set an environment variable
echo $VAR
Print a variable
env
Show all environment variables
unset VAR
Remove a variable
printenv PATH
Print a specific env variable
source ~/.bashrc
Reload shell config
which cmd
Show path to a command
type cmd
Show how a command is interpreted
Detailed sections
Pipes — the real power of the terminal
Pipes (|) connect commands so the output of one becomes the input of the next.
# Find all .js files and count themfind . -name "*.js" | wc -l# See the 10 largest filesdu -sh * | sort -rh | head -10# Search running processes for 'node' and kill themps aux | grep node | awk '{print $2}' | xargs kill# See only unique lines in a filecat file.txt | sort | uniq# Count occurrences of each wordcat file.txt | tr ' ' '\n' | sort | uniq -c | sort -rn | head -20
Grep — search like a pro
# Search recursively, show filename and line numbergrep -rn "TODO" ./src# Search for multiple patternsgrep -E "error|warning|critical" app.log# Show context around matches (3 lines before and after)grep -C 3 "error" app.log# Count matches per filegrep -rc "TODO" ./src# Exclude a directorygrep -r "pattern" . --exclude-dir=node_modules
Find — locate files quickly
# Find and delete all .DS_Store filesfind . -name ".DS_Store" -delete# Find files modified in the last 24 hoursfind . -mtime -1 -type f# Find files larger than 100MBfind . -size +100M -type f# Execute a command on each resultfind . -name "*.log" -exec rm {} \;# Find empty directoriesfind . -type d -empty
# Every minute* * * * * /path/to/script.sh# Every day at midnight0 0 * * * /path/to/script.sh# Every Monday at 9am0 9 * * 1 /path/to/script.sh# Every 15 minutes*/15 * * * * /path/to/script.sh# First day of every month at noon0 12 1 * * /path/to/script.sh
List cron jobs: crontab -l
Remove all cron jobs: crontab -r
SSH essentials
# Connect to a serverssh[email protected]# Connect on a non-standard portssh -p 2222 user@host# Copy a file to a serverscp localfile.txt user@host:/remote/path/# Copy a directory to a serverscp -r localdir/ user@host:/remote/path/# Generate an SSH key pairssh-keygen -t ed25519 -C "[email protected]"# Copy your public key to a server (enables passwordless login)ssh-copy-id user@host# SSH tunnel (forward remote port 5432 to localhost)ssh -L 5432:localhost:5432 user@host
Writing shell scripts
#!/bin/bashset -e # exit on any errorset -u # error on undefined variables# VariablesNAME="world"echo "Hello, $NAME!"# Conditionalsif [ -f "file.txt" ]; then echo "File exists"else echo "File not found"fi# Loopsfor file in *.js; do echo "Processing $file"done# Functionsgreet() { echo "Hello, $1!"}greet "developer"# Command substitutionDATE=$(date +%Y-%m-%d)echo "Today is $DATE"
Make it executable: chmod +x script.sh
Run it: ./script.sh