Linux Commands Cheat Sheet: Essential Commands Every Developer Needs
The essential Linux commands every developer should know — file management, text processing, permissions, networking, process management, and shell scripting basics.
DevToolsHub Team22 min read1,349 words
Navigation and File Management
Moving Around
# Print current directory
pwd
# Change directory
cd /path/to/dir
cd ~ # Home directory
cd - # Previous directory
cd .. # Parent directory
cd ../.. # Two levels up
# List files
ls # Basic listing
ls -la # Long format, show hidden files
ls -lh # Human-readable file sizes
ls -lt # Sort by modification time
ls -lS # Sort by file size
ls -R # Recursive listing
File Operations
# Create files
touch file.txt # Create empty file
echo "hello" > file.txt # Create with content
echo "more" >> file.txt # Append to file
# Create directories
mkdir mydir # Create directory
mkdir -p path/to/nested/dir # Create nested directories
# Copy
cp file.txt copy.txt # Copy file
cp -r dir/ dir_copy/ # Copy directory recursively
cp -i file.txt dest/ # Interactive (confirm overwrite)
# Move / Rename
mv file.txt newname.txt # Rename
mv file.txt /path/to/dest/ # Move
mv -i file.txt dest/ # Interactive
# Delete
rm file.txt # Delete file
rm -r dir/ # Delete directory recursively
rm -rf dir/ # Force delete (no confirmation)
rm -i file.txt # Interactive (confirm)
# Find files
find . -name "*.js" # Find by name
find . -name "*.log" -delete # Find and delete
find . -type f -size +100M # Files larger than 100MB
find . -type f -mtime -7 # Modified in last 7 days
find . -type f -empty # Empty files
find /path -name "*.txt" -exec grep -l "pattern" {} \;
Viewing Files
# View entire file
cat file.txt
# View with line numbers
cat -n file.txt
# View first/last lines
head file.txt # First 10 lines
head -n 20 file.txt # First 20 lines
tail file.txt # Last 10 lines
tail -n 20 file.txt # Last 20 lines
tail -f logfile.log # Follow (live updates)
# Page through a file
less file.txt # Scrollable viewer
# In less: q=quit, /=search, n=next match, g=top, G=bottom
# View file with syntax highlighting
bat file.txt # If bat is installed
Text Processing
grep — Search Text
# Search for pattern in file
grep "error" logfile.log
# Case-insensitive search
grep -i "error" logfile.log
# Recursive search in directory
grep -r "TODO" src/
# Show line numbers
grep -n "function" app.js
# Count matches
grep -c "error" logfile.log
# Show only filenames with matches
grep -l "import" src/*.ts
# Invert match (lines NOT containing pattern)
grep -v "debug" logfile.log
# Extended regex
grep -E "error|warning|critical" logfile.log
# Context lines (before/after match)
grep -B 2 -A 2 "error" logfile.log
sed — Stream Editor
# Replace first occurrence per line
sed 's/old/new/' file.txt
# Replace all occurrences
sed 's/old/new/g' file.txt
# Replace in-place (modify file)
sed -i 's/old/new/g' file.txt
# Delete lines matching pattern
sed '/pattern/d' file.txt
# Delete empty lines
sed '/^$/d' file.txt
# Print only matching lines
sed -n '/pattern/p' file.txt
# Replace on specific line
sed '3s/old/new/' file.txt
awk — Text Processing
# Print specific columns
awk '{print $1, $3}' file.txt
# Print with custom separator
awk -F',' '{print $1, $2}' data.csv
# Filter rows
awk '$3 > 100' data.txt
# Sum a column
awk '{sum += $1} END {print sum}' numbers.txt
# Count lines
awk 'END {print NR}' file.txt
# Print unique lines
awk '!seen[$0]++' file.txt
Other Text Tools
# Sort lines
sort file.txt # Alphabetical
sort -n file.txt # Numeric
sort -r file.txt # Reverse
sort -u file.txt # Unique only
sort -t',' -k2 -n data.csv # Sort CSV by 2nd column
# Remove duplicate lines
uniq file.txt # Remove adjacent duplicates
sort file.txt | uniq # Remove all duplicates
sort file.txt | uniq -c # Count occurrences
# Count lines, words, characters
wc file.txt # All three
wc -l file.txt # Lines only
wc -w file.txt # Words only
# Cut columns
cut -d',' -f1,3 data.csv # Fields 1 and 3
cut -c1-10 file.txt # Characters 1-10
# Translate characters
tr 'a-z' 'A-Z' < file.txt # Lowercase to uppercase
tr -d '\n' < file.txt # Remove newlines
tr -s ' ' < file.txt # Squeeze spaces
Permissions
# View permissions
ls -la
# Permission format: -rwxrwxrwx
# - = file type (- file, d directory, l symlink)
# rwx = owner permissions (read, write, execute)
# rwx = group permissions
# rwx = other permissions
# Change permissions (symbolic)
chmod u+x script.sh # Add execute for owner
chmod g+w file.txt # Add write for group
chmod o-r file.txt # Remove read for others
chmod a+r file.txt # Add read for all
# Change permissions (numeric)
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod 600 secret.key # rw-------
chmod -R 755 dir/ # Recursive
# Common permission patterns:
# 755 — Executable scripts, directories
# 644 — Regular files
# 600 — Private files (SSH keys, secrets)
# 700 — Private directories
# Change ownership
chown user:group file.txt
chown -R user:group dir/
Process Management
# View running processes
ps aux # All processes
ps aux | grep node # Filter by name
top # Interactive process viewer
htop # Better interactive viewer
# Kill processes
kill PID # Graceful stop (SIGTERM)
kill -9 PID # Force kill (SIGKILL)
killall node # Kill all by name
pkill -f "node server" # Kill by pattern
# Background processes
command & # Run in background
jobs # List background jobs
fg %1 # Bring job 1 to foreground
bg %1 # Resume job 1 in background
nohup command & # Run even after logout
# Ctrl+Z = suspend current process
# Ctrl+C = interrupt (kill) current process
Networking
# Download files
curl https://example.com # GET request
curl -o file.zip https://example.com/file # Save to file
curl -X POST -d '{"key":"value"}' -H "Content-Type: application/json" https://api.example.com
wget https://example.com/file.zip # Download file
# Network info
ifconfig # Network interfaces
ip addr # Modern alternative
hostname -I # Show IP address
# DNS lookup
nslookup example.com
dig example.com
# Test connectivity
ping example.com
ping -c 4 example.com # 4 pings only
# Check open ports
netstat -tlnp # Listening ports
ss -tlnp # Modern alternative
lsof -i :3000 # What's using port 3000
# SSH
ssh user@host # Connect
ssh -p 2222 user@host # Custom port
ssh -i key.pem user@host # With key file
scp file.txt user@host:/path/ # Copy file to remote
scp user@host:/path/file.txt . # Copy file from remote
Disk and System
# Disk usage
df -h # Filesystem usage
du -sh dir/ # Directory size
du -sh * | sort -rh | head -10 # Top 10 largest items
ncdu /path # Interactive disk usage
# System info
uname -a # System information
cat /etc/os-release # OS version
free -h # Memory usage
uptime # System uptime
whoami # Current user
Compression
# tar (archive)
tar -czf archive.tar.gz dir/ # Create gzipped archive
tar -xzf archive.tar.gz # Extract gzipped archive
tar -xzf archive.tar.gz -C /dest/ # Extract to specific directory
tar -tf archive.tar.gz # List contents
# zip
zip -r archive.zip dir/ # Create zip
unzip archive.zip # Extract zip
unzip -l archive.zip # List contents
# gzip
gzip file.txt # Compress (replaces original)
gunzip file.txt.gz # Decompress
Shell Shortcuts
# History
history # Show command history
!! # Repeat last command
!grep # Repeat last grep command
Ctrl+R # Search history
# Navigation
Ctrl+A # Move to start of line
Ctrl+E # Move to end of line
Ctrl+W # Delete word before cursor
Ctrl+U # Delete to start of line
Ctrl+K # Delete to end of line
Ctrl+L # Clear screen
# Piping and redirection
command > file.txt # Redirect stdout to file
command >> file.txt # Append stdout to file
command 2> error.log # Redirect stderr
command &> all.log # Redirect both
command1 | command2 # Pipe stdout to next command
command1 && command2 # Run command2 if command1 succeeds
command1 || command2 # Run command2 if command1 fails
linuxlinux commandsbashterminalcommand linelinux cheat sheetshellcli