Mastering Linux: 10 Essential Commands Every Software Engineer Should Know

Linux is at the heart of modern software development, powering everything from servers and cloud infrastructure to local development environments. Whether youβre a DevOps engineer, system administrator, or software developer, mastering Linux commands can significantly improve your productivity and troubleshooting skills. In this blog, weβll explore 10 essential Linux commands that every engineer should know.
1. Monitor System Performance
top & htop
Displays real-time system performance, including CPU and memory usage, running processes, and overall resource utilization.
Checking running processes and CPU usage
top
Output

π Use htop for a more user-friendly version with color-coded output.

2. Process Management
1. ps - Process Status
Lists all currently running processes along with their Process IDs (PIDs) and resource consumption.
Example: List all running processes
ps aux
Output

π Use ps aux | grep python to filter processes related to Python.
ps aux | grep python
2. pgrep - Find Process IDs
Searches for specific processes by name and retrieves their PIDs.
Find the PID of a running process
pgrep nginx
Output
2593
2594
π Use pgrep -l nginx to display both the PID and process name.
pgrep -l nginx

3. pstree - Process Hierarchy
Displays the hierarchical relationship between processes, showing which process triggered others.
View process tree for a specific process
pstree
Output

3. Network Connection Inspection
Shows active network connections, listening ports, and protocol usage, helping diagnose network-related issues.
netstat
List active TCP connections
netstat -tuln
Output

π Use netstat -ltn to check listening ports.
netstat -ltn
4. Capture & Analyze Network Traffic
tcpdump
Captures packets traveling through the network, helping identify latency issues and packet loss.
Capture HTTP packets
First, you need to find out the primary network interface.
To do this, run the command ifconfig.

In this case, it's - eth0
sudo tcpdump -i eth0 port 80
Output

And suppose you are trying to check port 80, then
sudo tcpdump -i eth0 port 80
π Use tcpdump -w capture.pcap to save packets for analysis.
5. Connectivity Troubleshooting
ping & traceroute
Ping a website
Tests network connectivity by sending packets to a remote host and measuring response time.
ping google.com -c 5
Output

Trace the route of a website
Shows the path packets take between your system and a target server, identifying network bottlenecks.
traceroute google.com
Output

6. Disk Space Analysis
df & du
Check disk space usage
df: Displays available and used disk space for each mounted file system.
df -h
Output
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 50G 30G 20G 60% /
To check disk space usage of a particular folder
du: Shows the space used by a specific directory or file, useful for pinpointing large storage consumers.
du -sh /var/log
Output

7. Memory Usage Inspection
free
Displays memory usage statistics, including total, used, and free RAM, helping manage resource allocation.
Check RAM usage
free -h
Output
total used free shared buff/cache available
Mem: 16G 8G 4G 1G 4G 7G
Swap: 2G 1G 1G
π Use watch free -h to continuously monitor RAM usage.
watch free -h
8. System Log Analysis
journalctl
Retrieves logs for services managed by systemd, allowing troubleshooting of crashes and errors.
View logs for a service
journalctl -u nginx
Output (Partial)
May 26 22:00:15 server nginx[2584]: Starting nginx service...
May 26 22:01:00 server systemd[1]: nginx.service: Main process exited, code=exited, status=1/FAILURE
π Use journalctl -b to all the logs.
journalctl -b
π Use journalctl -n 50 to fetch the last 50 logs.
journalctl -n 50
9. Identify Port & File Usage
lsof
Lists open files or identifies processes using specific ports, useful in resolving port conflicts.
Find processes using port 8080
lsof -i :8080
Output
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
python3 1024 root 16u IPv4 104857 0t0 TCP *:http-alt (LISTEN)
π Use lsof -p $(pgrep nginx) to check files opened by Nginx.
10. Log File Analysis
tail & head
View the last 10 lines of a log file
Displays the last few lines of a file, commonly used to monitor logs in real time.
tail -n 10 /var/log/nginx/error.log
Output
[error] 3456#3456: *12 directory index of "/var/www/html/" is forbidden, client: 192.168.1.12
[error] 3456#3456: *15 File not found: /var/www/html/favicon.ico
π Use tail -f /var/log/syslog to stream logs in real time.
tail -f /var/log/syslog
Viewing the first 10 lines of a file
Viewing the first 10 lines of a file
head -n 10 /var/log/syslog
Expected Output
May 28 04:00:01 server systemd[1]: Starting Daily Cleanup Service...
May 28 04:00:02 server kernel: [123456.789012] eth0: Link is Up - 1Gbps Full Duplex
May 28 04:00:03 server sshd[5678]: Accepted password for user from 192.168.1.10 port 54321 ssh2
May 28 04:00:04 server systemd[1]: Started Apache Web Server.
May 28 04:00:05 server apache2[6789]: [notice] Apache/2.4.41 (Ubuntu) started successfully.
May 28 04:00:06 server systemd[1]: Started MySQL Database Server.
May 28 04:00:07 server mysqld[7890]: [info] MySQL server ready for connections.
May 28 04:00:08 server systemd[1]: Finished Daily Cleanup Service.
May 28 04:00:09 server systemd[1]: Running scheduled tasks...
May 28 04:00:10 server systemd[1]: System maintenance completed.
π Use head -n 20 /var/log/syslog to view the first 20 lines instead.
Bonus 1: Linux Shortcut
Reverse search (Ctrl + R)
Quickly retrieve past commands

Press the right arrow key to select the command.
Bonus 2: Customizing terminal prompt
Modify your shell prompt.
export PS1="Hey There $ "

Conclusion
These Linux commands are indispensable for software engineers working with servers, applications, and troubleshooting environments. Mastering them ensures better system performance, quicker issue resolution, and efficient resource management.






