Essential Advanced Linux Commands Every Programmer Should Master
This guide walks through a collection of powerful Linux commands—including xargs for batch processing, nohup for background jobs, ps and sort for identifying high‑memory or CPU processes, multitail for simultaneous log viewing, ping logging with awk, netstat for connection stats, and ssh port forwarding—providing concrete examples and command syntax to help programmers streamline system administration tasks.
Introduction
The author shares a set of practical, advanced Linux commands that can make scripts shorter and system‑administration tasks more efficient. Each command is illustrated with a concrete example and the exact syntax to use.
1. Using xargs for batch processing
The xargs command can take the output of one command and feed it as arguments to another, avoiding intermediate files. Example: find all .conf files and run file on each. find / -name *.conf -type f -print | xargs file The result shows the file type of each .conf file.
Another use is to combine find with tar to archive the matched files directly:
find / -name *.conf -type f -print | xargs tar cjf test.tar.gz2. Running commands or scripts in the background
Long‑running operations such as database dumps should continue after the terminal is closed. Using nohup keeps the process alive and redirects output to a file.
nohup mysqldump -uroot -pXXXXX --all-databases > ./alldatabases.sql &If you prefer to hide the password, omit the trailing & and later suspend the job ( Ctrl+Z) and resume it in the background with bg. The output and any errors are written to nohup.out in the current directory.
3. Finding processes that consume the most memory
To locate memory‑hungry processes, pipe ps output to sort and display the top entries: ps -aux | sort -rnk 4 | head -20 The fourth column is the memory‑usage percentage; the last column shows the corresponding process.
4. Finding processes that consume the most CPU
Similarly, sorting by the third column reveals the highest CPU consumers: ps -aux | sort -rnk 3 | head -20 The third column is the CPU‑usage percentage.
5. Viewing multiple logs simultaneously with multitail
multitailcan display several log files in one terminal, with optional highlighting and filtering. Install it:
wget ftp://ftp.is.co.za/mirror/ftp.rpmforge.net/redhat/el6/en/x86_64/dag/RPMS/multitail-5.2.9-1.el6.rf.x86_64.rpm
yum -y localinstall multitail-5.2.9-1.el6.rf.x86_64.rpmExample: watch /var/log/secure for the keyword “Accepted” while simultaneously showing a live ping to Baidu:
multitail -e "Accepted" /var/log/secure -l "ping baidu.com"6. Continuously pinging and logging results
To record ping output with timestamps, use awk to append the current time and redirect to a log file:
ping api.jpush.cn | awk '{ print $0 " " strftime("%Y-%m-%d %H:%M:%S",systime()) }' >> /tmp/jiguang.log &The log file receives one line per second.
7. Checking TCP connection states
Listing the state column of all TCP connections helps analyse whether connections are being released or if an attack is occurring:
netstat -nat | awk '{print $6}' | sort | uniq -c | sort -rn8. Finding the top IPs requesting port 80
When traffic spikes, identify the IPs that most frequently access port 80. The following pipeline extracts the source IP, counts occurrences, and shows the top 20:
netstat -anlp | grep 80 | grep tcp | awk '{print $5}' \
| awk -F: '{print $1}' | sort | uniq -c | sort -nr | head -n209. Using ssh for port forwarding
sshcan forward a local port to a remote host, useful when a bastion host must access an internal service without exposing it. Example: forward local port 9200 on the bastion (192.168.1.15) to Elasticsearch’s 9200 on 192.168.1.19.
ssh -p 22 -C -f -N -g -L \
9200:192.168.1.19:9200 [email protected]After the command, connecting to 192.168.1.15:9200 actually reaches 192.168.1.19:9200. The prerequisite is that SSH keys have been exchanged.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Linux Tech Enthusiast
Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
