Linux Commands Every Software Engineer Must Know
When I moved into software engineering, Linux stopped being something I occasionally used and became something I lived inside. Every server I've worked on runs Linux. Every deployment, every debug session, every cron job — all of it happens in a terminal.
Most tutorials give you a list of 50 commands and call it a day. That's not useful. What's useful is knowing why a command exists, when you actually reach for it, and what the output is telling you. That's what this post is.
1. Navigating the file system
You spend more time moving around directories than you'd expect. These three are constant.
pwd # where am I right now?
ls -lah # list files: permissions, sizes, hidden files
cd /var/log # change directory
The -lah flags on ls are worth memorising together. -l gives long format, -a shows hidden files, -h makes sizes human-readable.
$ ls -lah /var/log
total 128M
drwxr-xr-x 12 root root 4.0K Apr 5 09:12 .
-rw-r--r-- 1 root root 84M Apr 8 07:01 syslog
-rw-r----- 1 root adm 2.1M Apr 8 06:25 auth.log
2. Reading and searching files
cat filename.txt # print entire file
less filename.txt # scroll through large file (q to quit)
head -n 20 filename.txt # first 20 lines
tail -n 50 filename.txt # last 50 lines
tail -f /var/log/syslog # follow a log in real time
tail -f is the one you'll use most during debugging. It streams new lines as they're written. Combine it with grep for focused monitoring:
grep "ERROR" /var/log/app.log # find ERROR lines
grep -i "timeout" /var/log/app.log # case-insensitive
grep -r "database" /etc/myapp/ # search recursively
tail -f /var/log/app.log | grep "ERROR" # live error stream only
3. File permissions
This trips up almost every engineer at least once. Here's how to read the permission string:
$ ls -l script.sh
-rwxr-xr-- 1 vijay dev 1.2K Apr 8 10:00 script.sh
# └─ owner:rwx │ group:r-x │ others:r--
chmod 755 script.sh # rwx for owner, r-x for group/others
chmod +x script.sh # add execute for everyone
chown vijay:dev file.txt # change owner and group
4. Process management
ps aux # all running processes
ps aux | grep python # filter by name
top # live resource usage view
kill 1234 # send SIGTERM
kill -9 1234 # force kill (SIGKILL)
lsof -i :5432 # what's using PostgreSQL port?
ss -tulnp | grep 5432 # modern alternative to netstat
5. Disk and memory
df -h # disk usage per filesystem
du -sh /var/log/* # size of each item in a folder
free -h # memory: total, used, free, cached
# find what's eating disk space, sorted by size
du -sh /var/log/* | sort -rh | head -10
$ free -h
total used free buff/cache available
Mem: 7.7G 3.1G 512M 4.1G 4.2G
6. SSH and remote access
ssh vijay@192.168.1.100 # connect to remote server
ssh -i ~/.ssh/mykey.pem user@host # use specific key
scp file.txt vijay@host:/tmp/ # copy file to remote
scp vijay@host:/tmp/file.txt . # copy file from remote
# generate a key pair
ssh-keygen -t ed25519 -C "vijay@myserver"
# copy public key to remote (no more password prompts)
ssh-copy-id vijay@192.168.1.100
7. Finding files
find /etc -name "*.conf" # all .conf files
find /home -type f -mtime -7 # modified last 7 days
find /tmp -size +100M # files over 100MB
find . -name "*.log" | xargs grep "refused"
8. Cron jobs
crontab -e # edit your crontab
crontab -l # list current cron jobs
# Syntax: minute hour day month weekday command
# ┌──── minute (0-59)
# │ ┌── hour (0-23)
# │ │ ┌─ day (1-31)
# │ │ │ ┌ month (1-12)
# │ │ │ │ ┌ weekday (0=Sun)
# * * * * * command
30 2 * * * /home/vijay/scripts/backup.sh # 2:30am daily
0 0 * * 0 /home/vijay/scripts/cleanup.sh # Sunday midnight
*/5 * * * * /home/vijay/scripts/health.sh >> /var/log/health.log 2>&1
9. Piping — where Linux gets powerful
# count ERROR lines in a log
grep "ERROR" /var/log/app.log | wc -l
# top 10 processes by memory
ps aux --sort=-%mem | head -10
# top IPs hitting your nginx server
cat /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -rn
# redirect output and errors to a file
./script.sh > output.log 2>&1
10. Putting it all together
A real debugging session on a production server usually follows this sequence:
# 1. SSH in
ssh vijay@prod-server-01
# 2. Check disk and memory first — always
df -h && free -h
# 3. What's using all the CPU?
ps aux --sort=-%cpu | head -15
# 4. Check recent app logs
tail -n 100 /var/log/app/app.log | grep -i "error\|warn\|fail"
# 5. Is the app listening on the right port?
ss -tulnp | grep 8080
# 6. Any system-level issues?
sudo tail -n 50 /var/log/syslog
That order covers 90% of production incidents. Run it before reaching for anything else.
The terminal feels slow and unfamiliar at first. After a few months of daily use it becomes faster than any GUI tool for the same tasks. Learn these until they're automatic — the speed gain is real.
Next post: How Linux file permissions actually work — chmod, chown, and umask explained in depth.
Comments
Post a Comment