Essential Commands
These will cover 90% of what you need.
File Operations
# List files
ls -la # Long format, show hidden
# Navigate
cd /var/www # Absolute path
cd ../ # Up one directory
cd ~ # Home directory
# Copy/Move/Delete
cp file.txt backup.txt
cp -r folder/ backup/
mv old.txt new.txt
rm file.txt
rm -rf folder/ # Careful with this one
Searching
# Find files
find . -name "*.php"
find /var/log -mtime -1 # Modified in last day
# Search file contents
grep "error" log.txt
grep -r "TODO" ./src # Recursive
grep -i "warning" log.txt # Case insensitive
Text Processing
# View files
cat file.txt
head -20 file.txt # First 20 lines
tail -f log.txt # Follow new lines
# Count
wc -l file.txt # Line count
# Filter columns
awk '{print $1}' file.txt
# Replace text
sed 's/old/new/g' file.txt
Pipes
Chain commands together:
# Find PHP files containing "class"
find . -name "*.php" | xargs grep "class"
# Count lines of code
find . -name "*.js" | xargs wc -l | tail -1
# Filter logs
cat access.log | grep "500" | awk '{print $1}' | sort | uniq -c
SSH
# Connect
ssh user@server.com
# Copy files
scp file.txt user@server:/path/
scp -r folder/ user@server:/path/
# SSH key
ssh-keygen -t ed25519
ssh-copy-id user@server
Process Management
# Running processes
ps aux
ps aux | grep nginx
# Kill process
kill 1234 # Graceful
kill -9 1234 # Force
# Background jobs
./script.sh & # Run in background
nohup ./script.sh & # Survives logout
