Linux Commands Every Developer Must Know — Complete DevOps Reference

Sanjeev SharmaSanjeev Sharma
7 min read

Advertisement

Introduction

Why This Matters

Linux powers over 96% of the world's top web servers and virtually every cloud computing platform. Effective Linux command-line proficiency separates engineers who can investigate and resolve production incidents from those who are stuck waiting for help. Whether you are debugging a memory leak, investigating disk exhaustion, or analyzing network connectivity — these commands are your primary diagnostic tools.

File System Navigation and Operations

# Navigation
pwd                         # print working directory
ls -la                      # list with permissions, hidden files, sizes
ls -lh --sort=size          # sort by size, human-readable
tree -L 2                   # tree view, 2 levels deep
cd -                        # go to previous directory
 
# File creation and editing
touch file.txt              # create empty file or update timestamp
mkdir -p a/b/c              # create nested directories
cp -r source/ dest/         # recursive copy
mv old-name new-name        # rename or move
rm -rf directory/           # delete directory (no confirmation)
ln -s /path/to/file link    # create symbolic link
 
# File content
cat file.txt                # print entire file
less file.txt               # paginated view (q to quit)
head -n 20 file.txt         # first 20 lines
tail -n 50 file.txt         # last 50 lines
tail -f /var/log/app.log    # follow live log output
wc -l file.txt              # count lines
 
# Search
grep -r "pattern" /var/log/         # recursive search
grep -n "ERROR" app.log             # show line numbers
grep -i "error" app.log             # case-insensitive
grep -A 3 -B 3 "exception" app.log  # 3 lines context before/after
grep -v "healthcheck" access.log    # exclude matching lines
 
find /var/log -name "*.log" -mtime -1    # logs modified in last day
find /opt -name "*.jar" -size +100M      # files larger than 100MB
find /tmp -type f -mtime +7 -delete      # delete files older than 7 days
 
# Archives
tar -czf archive.tar.gz directory/      # compress directory
tar -xzf archive.tar.gz -C /tmp/        # extract to /tmp
tar -tzf archive.tar.gz                 # list contents
zip -r archive.zip directory/
unzip archive.zip -d /tmp/

Permissions and Ownership

# View permissions
ls -la
stat file.txt
 
# Octal permissions
# 7 = rwx (4+2+1)
# 6 = rw-  (4+2)
# 5 = r-x  (4+1)
# 4 = r--  (4)
 
chmod 755 script.sh         # rwxr-xr-x — executable script
chmod 644 config.txt        # rw-r--r-- — regular file
chmod 600 ~/.ssh/id_rsa     # rw------- — private key
chmod +x script.sh          # add execute bit
chmod -R 755 /var/www/      # recursive
 
chown user:group file.txt   # change owner and group
chown -R www-data /var/www/ # recursive ownership
sudo chown root:root /etc/cron.d/myjob  # root-owned cron
 
# ACLs (Access Control Lists)
getfacl file.txt
setfacl -m u:deploy:rw file.txt   # give deploy user rw access

Process Management

# View processes
ps aux                      # all processes with CPU/memory
ps aux | grep node          # filter by process name
top                         # live process monitor (q to quit)
htop                        # enhanced top (if installed)
pgrep -l nginx              # find process IDs by name
 
# Kill processes
kill PID                    # graceful SIGTERM
kill -9 PID                 # force SIGKILL
killall nginx               # kill all processes with name
pkill -f "python script.py" # kill by pattern
 
# Background jobs
command &               # run in background
nohup command &         # run immune to hangup
jobs                    # list background jobs
fg %1                   # bring job 1 to foreground
bg %1                   # send stopped job to background
 
# System resource usage
free -h                     # RAM usage
vmstat 1 10                 # VM stats, 1s intervals, 10 samples
iostat -x 1                 # disk I/O stats
lsof -i :3000               # processes using port 3000
lsof -u username            # files opened by user

Disk and Storage

# Disk usage
df -h                       # filesystem disk usage
df -h /var                  # specific path
du -sh /var/log/            # directory total size
du -sh /* 2>/dev/null | sort -rh | head  # find large directories
du -sh /var/log/* | sort -rh | head -20  # top 20 by size
 
# Find disk hogs
find / -size +1G -type f 2>/dev/null   # files larger than 1GB
find /var/log -name "*.gz" -delete     # delete compressed logs
 
# Disk performance
dd if=/dev/zero of=/tmp/test bs=1M count=1024  # write speed test
hdparm -tT /dev/sda                            # disk read speed
 
# Mount and partitions
lsblk                       # list block devices
fdisk -l                    # list disk partitions (root)
mount | column -t           # show mounted filesystems
df -iT                      # inodes usage

Networking

# Network interfaces and IP
ip addr show                # list all interfaces and IPs
ip addr show eth0           # specific interface
ip route show               # routing table
hostname -I                 # local IP addresses
 
# Connectivity testing
ping -c 4 google.com        # ICMP ping (4 packets)
traceroute example.com      # trace route to host
mtr example.com             # continuous traceroute
curl -I https://example.com # HTTP headers only
curl -v https://example.com # verbose HTTP request
wget -O /dev/null http://...# download speed test
 
# DNS
nslookup example.com        # DNS lookup
dig example.com A           # DNS A record
dig +short example.com      # short output
dig @8.8.8.8 example.com    # query specific DNS server
 
# Open ports and connections
ss -tlnp                    # listening TCP ports and processes
ss -s                       # socket statistics summary
netstat -tlnp               # older alternative to ss
lsof -i TCP:443             # processes on port 443
 
# Firewall
sudo ufw status verbose     # Ubuntu firewall status
sudo ufw allow 443/tcp      # allow HTTPS
iptables -L -n              # list iptables rules

System Information and Services

# System info
uname -a                    # kernel and OS info
cat /etc/os-release         # OS distribution info
uptime                      # system uptime and load average
who                         # logged-in users
last | head -20             # recent logins
 
# Systemd services
systemctl status nginx      # service status
systemctl start nginx       # start service
systemctl stop nginx        # stop service
systemctl restart nginx     # restart
systemctl reload nginx      # reload config (no downtime)
systemctl enable nginx      # auto-start on boot
systemctl disable nginx     # remove auto-start
journalctl -u nginx -f      # follow service logs
journalctl -u nginx --since "1 hour ago"  # logs from last hour
 
# Cron jobs
crontab -l                  # list cron jobs for current user
crontab -e                  # edit cron jobs
crontab -l -u www-data      # list cron for specific user
cat /etc/cron.d/*           # system-wide cron jobs

Common Mistakes

  • Using rm -rf / or rm -rf * without double-checking the current directory — always verify pwd before recursive deletions
  • Running production debug commands without understanding side effects — strace, tcpdump, and lsof add overhead
  • Killing processes with kill -9 before trying kill-9 does not allow processes to clean up, potentially leaving lock files or corrupt state
  • Not using sudo -l to check sudo permissions before escalating — always know what you can do before doing it
  • Ignoring ulimit settings — open file limits and process limits cause mysterious failures at scale

Best Practices

  • Use screen or tmux for long-running commands on remote servers — prevents losing work when SSH disconnects
  • Pipe commands to tee when you need both terminal output and a file: command | tee output.txt
  • Use history | grep to find previously executed commands rather than retyping complex one-liners
  • Add set -euo pipefail to scripts — errors exit immediately rather than silently continuing
  • Use watch -n 2 'command' to refresh command output every 2 seconds for monitoring

Key Takeaways

  • find with -exec or -delete is the standard tool for bulk file operations based on name, age, or size
  • ss -tlnp replaces the deprecated netstat for listing listening ports and associated processes
  • Process load average in uptime shows 1/5/15 minute averages — values above CPU count indicate saturation
  • journalctl -u service --since "1 hour ago" is the modern way to view systemd service logs
  • lsof -i :PORT reveals which process owns a port — essential when a port appears already in use
  • df -h shows disk space by filesystem; du -sh /path shows how much a directory actually consumes
  • Permissions 755 (rwxr-xr-x) for directories and executables; 644 (rw-r--r--) for regular files is the standard baseline
  • tail -f follows log files in real time — combine with grep --line-buffered to filter live output

Advertisement

Sanjeev Sharma

Written by

Sanjeev Sharma

Full Stack Engineer · E-mopro

Related reading