Operations 10 min read

Master Essential Linux Ops: xargs, Background Jobs, Process Monitoring & More

This guide walks you through practical Linux operations—from using xargs for efficient file handling and running commands in the background, to monitoring high‑memory and high‑CPU processes, viewing multiple logs with multitail, continuous ping logging, checking TCP states, identifying top IPs on port 80, and leveraging SSH for port forwarding.

Efficient Ops
Efficient Ops
Efficient Ops
Master Essential Linux Ops: xargs, Background Jobs, Process Monitoring & More

Preface

After years of struggling with ad‑hoc scripts, the author shares concise explanations of advanced Linux commands to help both newcomers and seasoned operators write cleaner, more efficient scripts.

1. Practical xargs command

The xargs utility feeds the output of one command as arguments to another, simplifying tasks such as finding all .conf files and classifying them.

# find / -name *.conf -type f -print | xargs file

The result can be piped into other commands, for example to archive the files:

# find / -name *.conf -type f -print | xargs tar cjf test.tar.gz

2. Running commands or scripts in background

Use nohup to keep long‑running operations alive after the terminal closes, e.g., exporting all MySQL databases:

nohup mysqldump -uroot -pXXXXX --all-databases > ./alldatabases.sql &

If you prefer to enter the password interactively, run the command without &, then suspend it with Ctrl+Z and resume in the background with bg. Output and errors are captured in nohup.out.

3. Find processes with high memory usage

# ps -aux | sort -rnk 4 | head -20

The fourth column shows memory‑usage percentage; the last column lists the corresponding process.

4. Find processes with high CPU usage

# ps -aux | sort -rnk 3 | head -20

The third column indicates CPU‑usage percentage.

5. View multiple logs simultaneously

Install multitail to monitor several log files in one terminal with highlighting and filtering.

# wget ftp://ftp.is.co.za/mirror/ftp.rpmforge.net/redhat/el6/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.rpm

Example: watch /var/log/secure for the keyword “Accepted” while simultaneously pinging Baidu:

# multitail -e "Accepted" /var/log/secure -l "ping baidu.com"

6. Continuous ping logging

ping api.jpush.cn | awk '{ print $0 " " strftime("%Y-%m-%d %H:%M:%S",systime()) }' >> /tmp/jiguang.log &

The command appends a timestamped ping line to /tmp/jiguang.log every second.

7. Check TCP connection states

# netstat -nat | awk '{print $6}' | sort | uniq -c | sort -rn

8. Find top 20 IPs requesting port 80

# netstat -anlp | grep 80 | grep tcp | awk '{print $5}' | awk -F: '{print $1}' | sort | uniq -c | sort -nr | head -n20

9. SSH port forwarding

Forward port 9200 on a bastion host to an internal Elasticsearch server:

ssh -p 22 -C -f -N -g -L 9200:192.168.1.19:9200 [email protected]

After executing, accessing 192.168.1.15:9200 actually reaches 192.168.1.19:9200. Ensure SSH keys are exchanged beforehand.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

monitoringOpsShellSSHxargsmultitail
Efficient Ops
Written by

Efficient Ops

This public account is maintained by Xiaotianguo and friends, regularly publishing widely-read original technical articles. We focus on operations transformation and accompany you throughout your operations career, growing together happily.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.