PureTools

Linux Terminal: 50 Essential Commands

PureTools Team· 12 min read
Linux Terminal: 50 Essential Commands

Linux Terminal: The Commands You'll Use Every Day

Whether you're SSHing into a production server, running Docker containers, or just navigating your development machine, the Linux terminal is unavoidable. This isn't a comprehensive reference — it's the 50 commands you'll actually type most often, with the flags that matter.

Files and Navigation

# Where am I?
pwd

# List files (human-readable, all, long format)
ls -lah

# Change directory
cd /var/log
cd ..         # parent
cd ~          # home
cd -          # previous directory

# Create files and directories
touch file.txt
mkdir -p path/to/nested/dir

# Copy, move, rename
cp file.txt backup.txt
cp -r dir/ dir-backup/     # recursive
mv old-name.txt new-name.txt

# Remove (careful!)
rm file.txt
rm -rf directory/          # recursive, force — no undo!

Reading Files

# Print entire file
cat config.yml

# First/last lines
head -20 app.log
tail -50 app.log

# Follow log in real-time (indispensable for debugging)
tail -f /var/log/nginx/error.log

# Page through large files
less huge-file.log    # q to quit, / to search

# Count lines, words, characters
wc -l data.csv        # line count

Searching

# Find files by name
find . -name "*.js" -type f
find /var/log -name "*.log" -mtime -7   # modified in last 7 days

# Search file contents
grep "error" app.log
grep -r "TODO" src/                     # recursive
grep -rn "function" --include="*.ts"    # with line numbers, specific extension
grep -i "warning" app.log               # case insensitive

# Find and act
find . -name "*.tmp" -exec rm {} \;     # find and delete

Permissions

# View permissions
ls -la
# drwxr-xr-x  = directory, owner rwx, group r-x, others r-x

# Change permissions
chmod 755 script.sh     # rwxr-xr-x
chmod +x script.sh      # add execute
chmod 600 .env          # rw------- (owner only)

# Change ownership
chown user:group file
chown -R www-data:www-data /var/www/

Processes

# What's running?
ps aux
ps aux | grep nginx

# Interactive process viewer
top       # basic
htop      # better (install separately)

# Kill a process
kill PID
kill -9 PID              # force kill (SIGKILL)
killall nginx            # kill by name

# Run in background
nohup ./long-task.sh &   # survives logout

# Check what's listening on a port
ss -tulnp | grep 3000
lsof -i :3000

Disk

# Disk space overview
df -h

# Directory sizes
du -sh /var/log/
du -sh */ | sort -rh | head -10   # top 10 largest dirs

# Memory
free -h

Network

# Download
curl -O https://example.com/file.zip
wget https://example.com/file.zip

# HTTP request
curl -X POST https://api.example.com/data \
  -H "Content-Type: application/json" \
  -d '{"key": "value"}'

# DNS lookup
dig example.com
nslookup example.com

# Check connectivity
ping -c 4 google.com

# Show IP addresses
ip addr
hostname -I

Compression

# Create tar.gz
tar -czf archive.tar.gz directory/

# Extract tar.gz
tar -xzf archive.tar.gz

# Create/extract zip
zip -r archive.zip directory/
unzip archive.zip

Productivity Tips

# Command history
history | grep "docker"
!123              # re-run command #123
!!                # re-run last command
sudo !!           # re-run last command as root

# Pipe and redirect
cat file.txt | grep "error" | wc -l    # count error lines
command > output.txt       # overwrite
command >> output.txt      # append
command 2>&1               # redirect stderr to stdout

# Aliases (add to ~/.bashrc or ~/.zshrc)
alias ll='ls -lah'
alias gs='git status'
alias dc='docker compose'

Interactive reference: Linux Cheatsheet — searchable, categorized, click to copy any command.