Linux Command Line Essentials: 60+ Commands Every Developer Should Know
Linux Command Line Essentials: 60+ Commands Every Developer Should Know
The ultimate Linux command line reference for developers. Master 60+ essential commands for file management, text processing, networking, system administration, and productivity with practical examples.
Introduction: The Power of the Command Line
The command line is where software gets built. Despite decades of graphical interfaces, the terminal remains the most powerful, flexible, and efficient way to interact with computers. In 2026, with cloud computing, containerization, CI/CD pipelines, and remote development becoming the norm, command line proficiency is more important than ever.
This guide covers over 60 essential Linux commands organized by category. Each command includes practical examples that you will actually use in your daily work. Whether you are on Linux, macOS (which shares most commands), or Windows with WSL, these commands will boost your productivity.
Bookmark this page -- it is designed to be a reference you come back to whenever you need a quick reminder.
File and Directory Operations
Navigation
# Print current directory
pwd
# Output: /home/user/projects
# Change directory
cd /var/log # Absolute path
cd ../ # Parent directory
cd ~ # Home directory
cd - # Previous directory
# List files
ls # Basic listing
ls -la # Long format, including hidden files
ls -lah # Human-readable file sizes
ls -lt # Sort by modification time
ls -lS # Sort by file size
ls -R # Recursive listing
File Management
# Create files
touch newfile.txt # Create empty file or update timestamp
touch file1.txt file2.txt file3.txt # Create multiple files
# Copy files and directories
cp source.txt destination.txt # Copy a file
cp -r source_dir/ destination_dir/ # Copy directory recursively
cp -p file.txt backup.txt # Preserve permissions and timestamps
cp -i file.txt existing.txt # Interactive: prompt before overwrite
# Move and rename
mv oldname.txt newname.txt # Rename a file
mv file.txt /path/to/destination/ # Move a file
mv -i source.txt destination.txt # Interactive: prompt before overwrite
# Delete files and directories
rm file.txt # Delete a file
rm -r directory/ # Delete directory recursively
rm -rf directory/ # Force delete (use with extreme caution!)
rm -i file.txt # Interactive: confirm before deleting
# Create directories
mkdir new_directory # Create a directory
mkdir -p path/to/nested/directory # Create nested directories
mkdir -m 755 secure_dir # Create with specific permissions
File Information
# File type detection
file document.pdf
# Output: PDF document, version 1.7
file script.sh
# Output: Bourne-Again shell script, ASCII text executable
# File size and disk usage
du -sh directory/ # Total size of a directory
du -sh * # Size of each item in current directory
du -sh * | sort -rh # Sort by size, largest first
df -h # Disk space usage of all filesystems
df -h /dev/sda1 # Specific filesystem
# File statistics
stat filename.txt # Detailed file information
wc filename.txt # Line, word, and byte count
wc -l filename.txt # Line count only
wc -w filename.txt # Word count only
Our Word Counter tool provides similar word and character counting functionality for quick text analysis in your browser.
Text Processing
Text processing is one of the most powerful aspects of the Linux command line.
Viewing Files
# Display file contents
cat file.txt # Print entire file
cat -n file.txt # With line numbers
cat file1.txt file2.txt > merged.txt # Concatenate files
# View beginning/end of files
head file.txt # First 10 lines (default)
head -n 20 file.txt # First 20 lines
head -c 100 file.txt # First 100 bytes
tail file.txt # Last 10 lines
tail -n 20 file.txt # Last 20 lines
tail -f logfile.log # Follow: watch file for new lines
tail -f -n 50 logfile.log # Follow with last 50 lines
# Page through files
less file.txt # Scrollable file viewer
# Navigation in less:
# Space = next page, b = previous page
# / = search forward, ? = search backward
# g = beginning, G = end, q = quit
Searching with grep
# Basic search
grep "error" logfile.log # Find lines containing "error"
grep -i "error" logfile.log # Case-insensitive search
grep -n "error" logfile.log # Show line numbers
grep -c "error" logfile.log # Count matching lines
grep -v "debug" logfile.log # Invert: show lines NOT matching
# Recursive search
grep -r "TODO" src/ # Search all files in directory
grep -rn "import React" src/ # Recursive with line numbers
grep -rl "deprecated" src/ # Only show filenames
# Regular expressions
grep -E "error|warning" logfile.log # Extended regex: OR pattern
grep -E "^[0-9]{4}-" logfile.log # Lines starting with a year
grep -P "\d{3}-\d{4}" contacts.txt # Perl regex: phone numbers
# Context around matches
grep -A 3 "error" logfile.log # 3 lines After match
grep -B 2 "error" logfile.log # 2 lines Before match
grep -C 2 "error" logfile.log # 2 lines Context (before and after)
Test your regex patterns with our Regex Tester tool before using them in grep commands.
Text Transformation
# sed: stream editor for text transformation
sed 's/old/new/' file.txt # Replace first occurrence per line
sed 's/old/new/g' file.txt # Replace all occurrences
sed -i 's/old/new/g' file.txt # Edit file in place
sed -n '10,20p' file.txt # Print lines 10-20
sed '/^#/d' config.txt # Delete comment lines
sed '/^$/d' file.txt # Delete empty lines
# awk: pattern scanning and processing
awk '{print $1}' file.txt # Print first column
awk '{print $1, $3}' file.txt # Print columns 1 and 3
awk -F',' '{print $2}' data.csv # CSV: print second column
awk '{sum += $1} END {print sum}' numbers.txt # Sum a column
awk 'NR >= 10 && NR <= 20' file.txt # Print lines 10-20
awk '{print NR": "$0}' file.txt # Add line numbers
# sort: sort lines
sort file.txt # Alphabetical sort
sort -n numbers.txt # Numeric sort
sort -r file.txt # Reverse sort
sort -u file.txt # Sort and remove duplicates
sort -t',' -k2 -n data.csv # Sort CSV by second column numerically
# uniq: report or remove duplicate lines
sort file.txt | uniq # Remove adjacent duplicates
sort file.txt | uniq -c # Count occurrences
sort file.txt | uniq -d # Show only duplicates
# cut: extract columns
cut -d',' -f1,3 data.csv # Extract columns 1 and 3 from CSV
cut -c1-10 file.txt # Extract first 10 characters per line
# tr: translate characters
echo "HELLO" | tr 'A-Z' 'a-z' # Convert to lowercase
echo "hello" | tr 'a-z' 'A-Z' # Convert to uppercase
cat file.txt | tr -d '\r' # Remove carriage returns
cat file.txt | tr -s ' ' # Squeeze repeated spaces
Our Case Converter tool provides similar text case conversion functionality in your browser.
Text Comparison
# diff: compare files line by line
diff file1.txt file2.txt # Basic diff
diff -u file1.txt file2.txt # Unified format (like git diff)
diff -y file1.txt file2.txt # Side-by-side comparison
diff -r dir1/ dir2/ # Recursive directory comparison
diff --color file1.txt file2.txt # Colored output
# comm: compare sorted files line by line
comm file1.txt file2.txt # Three-column output
comm -12 file1.txt file2.txt # Lines common to both files
comm -23 file1.txt file2.txt # Lines only in file1
Permissions and Ownership
Understanding Permissions
-rwxr-xr-- 1 user group 4096 Mar 16 10:00 file.txt
βββ¬βββ¬βββ¬β
β β β βββ Other: read only
β β ββββββ Group: read and execute
β βββββββββ Owner: read, write, and execute
βββββββββββ Type: - = file, d = directory, l = symlink
chmod: Change Permissions
# Symbolic mode
chmod u+x script.sh # Add execute for owner
chmod g+rw file.txt # Add read/write for group
chmod o-w file.txt # Remove write for others
chmod a+r file.txt # Add read for all
# Numeric mode (octal)
chmod 755 script.sh # rwxr-xr-x
chmod 644 file.txt # rw-r--r--
chmod 600 private.key # rw------- (owner only)
chmod 777 file.txt # rwxrwxrwx (avoid in production!)
# Recursive
chmod -R 755 directory/ # Apply to directory and all contents
chown: Change Ownership
chown user file.txt # Change owner
chown user:group file.txt # Change owner and group
chown -R user:group directory/ # Recursive ownership change
Process Management
# View processes
ps # Current terminal processes
ps aux # All processes with details
ps aux | grep node # Find specific processes
top # Interactive process viewer
htop # Better interactive viewer (if installed)
# Process control
kill PID # Send SIGTERM (graceful shutdown)
kill -9 PID # Send SIGKILL (force kill)
kill -15 PID # Send SIGTERM explicitly
killall node # Kill all processes by name
pkill -f "node server" # Kill by command pattern
# Background and foreground
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 terminal closes
disown %1 # Detach job from terminal
# Process monitoring
watch -n 2 'ps aux | grep node' # Repeat command every 2 seconds
lsof -i :3000 # What process is using port 3000?
lsof -p PID # Files opened by a process
Networking
# Network information
ip addr show # Show network interfaces (Linux)
ifconfig # Show network interfaces (macOS/legacy)
hostname # Show hostname
hostname -I # Show IP address
# Connectivity testing
ping google.com # Test connectivity
ping -c 5 google.com # Send exactly 5 pings
traceroute google.com # Trace route to host
# DNS lookup
nslookup google.com # Query DNS
dig google.com # Detailed DNS query
dig +short google.com # Just the IP
# HTTP requests with curl
curl https://api.example.com # GET request
curl -o output.html https://example.com # Save to file
curl -I https://example.com # Headers only
curl -X POST -d '{"key":"value"}' \
-H "Content-Type: application/json" \
https://api.example.com/data # POST JSON
# Download files
wget https://example.com/file.zip # Download a file
wget -c https://example.com/big.zip # Resume incomplete download
curl -L -O https://example.com/file.zip # Download with curl
# Port scanning and connectivity
nc -zv host 80 # Check if port 80 is open
ss -tulnp # Show listening ports (Linux)
netstat -tulnp # Show listening ports (legacy)
lsof -i :8080 # Who is using port 8080?
For URL encoding in your API requests, use our URL Encoder tool.
Compression and Archives
# tar: archive files
tar -cf archive.tar files/ # Create tar archive
tar -czf archive.tar.gz files/ # Create gzip compressed archive
tar -cjf archive.tar.bz2 files/ # Create bzip2 compressed archive
tar -xf archive.tar # Extract tar archive
tar -xzf archive.tar.gz # Extract gzip archive
tar -xzf archive.tar.gz -C /target/ # Extract to specific directory
tar -tf archive.tar.gz # List contents without extracting
# zip/unzip
zip archive.zip file1 file2 # Create zip archive
zip -r archive.zip directory/ # Zip a directory
unzip archive.zip # Extract zip archive
unzip -l archive.zip # List contents
# gzip
gzip file.txt # Compress (replaces original)
gzip -k file.txt # Compress (keep original)
gzip -d file.txt.gz # Decompress
gunzip file.txt.gz # Decompress (alternative)
Environment and Shell
# Environment variables
echo $HOME # Print home directory
echo $PATH # Print PATH
echo $USER # Print current user
env # List all environment variables
export MY_VAR="value" # Set environment variable
unset MY_VAR # Remove environment variable
# Shell configuration
source ~/.bashrc # Reload bash configuration
source ~/.zshrc # Reload zsh configuration
echo $SHELL # Current shell
# Command history
history # Show command history
history | grep "docker" # Search history
!123 # Re-run command number 123
!! # Re-run last command
sudo !! # Re-run last command with sudo
Ctrl+R # Reverse search through history
# Aliases
alias ll='ls -la' # Create alias
alias gs='git status'
alias dc='docker-compose'
unalias ll # Remove alias
Piping and Redirection
One of the most powerful features of the command line is the ability to chain commands together.
# Pipes: send output of one command to another
ls -la | grep ".txt" # Find .txt files in listing
cat logfile.log | grep "error" | wc -l # Count error lines
ps aux | sort -k4 -rn | head -10 # Top 10 memory-consuming processes
history | awk '{print $2}' | sort | uniq -c | sort -rn | head -10 # Most used commands
# Output redirection
echo "hello" > file.txt # Write to file (overwrite)
echo "world" >> file.txt # Append to file
command 2> errors.log # Redirect stderr to file
command > output.log 2>&1 # Redirect both stdout and stderr
command > /dev/null 2>&1 # Discard all output
command &> /dev/null # Shorthand for above (bash)
# Input redirection
command < input.txt # Use file as input
command << EOF # Here document
line 1
line 2
EOF
# tee: write to file AND stdout
command | tee output.log # Display and save output
command | tee -a output.log # Display and append to file
Disk and Storage
# Disk usage
df -h # Filesystem disk usage
du -sh * # Size of items in current directory
du -sh * | sort -rh | head -20 # Top 20 largest items
ncdu / # Interactive disk usage explorer
# Find large files
find / -type f -size +100M 2>/dev/null # Files larger than 100MB
find . -type f -name "*.log" -size +10M # Large log files
# Symlinks
ln -s /path/to/target linkname # Create symbolic link
ln -sf /path/to/target linkname # Force create (overwrite)
readlink linkname # Show link target
Useful Combinations for Developers
Finding and Replacing Across Files
# Find all files containing a pattern
grep -rl "oldFunction" src/
# Find and replace across files
find src/ -type f -name "*.ts" -exec sed -i 's/oldFunction/newFunction/g' {} +
# Find TODO comments in codebase
grep -rn "TODO\|FIXME\|HACK" src/ --include="*.ts"
# Count lines of code
find src/ -name "*.ts" -o -name "*.tsx" | xargs wc -l | tail -1
# Find recently modified files
find . -type f -mtime -1 -name "*.ts" # Modified in last 24 hours
Log Analysis
# Most common errors in a log
grep "ERROR" app.log | awk '{print $5}' | sort | uniq -c | sort -rn | head -10
# Requests per minute from access log
awk '{print $4}' access.log | cut -d: -f1-2 | sort | uniq -c
# Watch logs in real-time with highlighting
tail -f app.log | grep --color=always -E "ERROR|WARNING|"
# Extract unique IP addresses
awk '{print $1}' access.log | sort -u | wc -l
Quick Server Tasks
# Start a quick HTTP server
python3 -m http.server 8000 # Python
npx serve . # Node.js
# Check if a port is in use
lsof -i :3000
ss -tlnp | grep 3000
# SSH shortcuts
ssh user@host # Connect to remote server
ssh -L 8080:localhost:3000 user@host # Port forwarding
scp file.txt user@host:/path/ # Copy file to remote
rsync -avz src/ user@host:/dest/ # Sync directories
Docker Commands
# Container management
docker ps # Running containers
docker ps -a # All containers
docker logs container_name # View container logs
docker logs -f container_name # Follow logs
docker exec -it container bash # Shell into container
docker stop $(docker ps -q) # Stop all running containers
# Image management
docker images # List images
docker image prune # Remove unused images
docker system prune -a # Remove everything unused
# Docker Compose
docker compose up -d # Start services in background
docker compose down # Stop and remove services
docker compose logs -f # Follow all service logs
Quick Reference Table
| Task | Command |
|---|---|
| Current directory | pwd |
| List files (detailed) | ls -la |
| Change directory | cd path/ |
| Create file | touch file.txt |
| Create directory | mkdir -p path/to/dir |
| Copy file | cp source dest |
| Move/rename | mv source dest |
| Delete file | rm file.txt |
| View file | less file.txt |
| Search in files | grep -rn "pattern" dir/ |
| Find files | find . -name "*.txt" |
| File permissions | chmod 755 file |
| Process list | ps aux |
| Kill process | kill -9 PID |
| Disk usage | du -sh * |
| Download file | curl -O URL |
| Compress | tar -czf archive.tar.gz dir/ |
| Extract | tar -xzf archive.tar.gz |
| Port check | lsof -i :PORT |
Conclusion
The command line is not just a tool -- it is a superpower. The commands in this guide represent the essential toolkit that every developer should have at their fingertips. Start with the basics, practice regularly, and gradually incorporate more advanced commands into your workflow.
The beauty of the command line is in composability: simple commands combined with pipes and redirection can accomplish incredibly complex tasks. Master these fundamentals, and you will be able to handle virtually any system administration, development, or debugging task that comes your way.
For your browser-based developer needs, check out our free online tools -- from regex testing and JSON formatting to Base64 encoding and hash generation.
Related Resources
- Git Commands Cheat Sheet -- Essential Git commands for version control
- Remote Work Developer Tools 2026 -- Tools for remote developers
- Password Security Guide -- Secure your systems and accounts
- Regex Tester -- Test grep patterns in your browser
- Hash Generator -- Generate SHA hashes online