Operations 10 min read

Boost Your Linux Ops: Master Xargs, Background Jobs, and Real‑Time Monitoring

This guide walks you through essential Linux operations techniques—including practical xargs usage, running scripts in the background with nohup, identifying high‑memory and high‑CPU processes, monitoring multiple logs with multitail, continuous ping logging, checking TCP connections, spotting top IPs, and SSH port forwarding—providing ready‑to‑use commands and examples.

Efficient Ops
Efficient Ops
Efficient Ops
Boost Your Linux Ops: Master Xargs, Background Jobs, and Real‑Time Monitoring

Introduction

After years of working in operations, I still remember starting with only simple commands and writing overly long, inefficient scripts. This article records useful advanced Linux commands for the benefit of both myself and others.

1. Practical xargs Command

The xargs command lets you pass the output of one command as arguments to another, simplifying tasks such as classifying files.

Example – find all .conf files under / and classify them: find / -name *.conf -type f -print | xargs file You can also combine find with tar to archive the matched files:

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

2. Running Commands or Scripts in the Background

To keep long‑running operations (e.g., database dumps) alive after the terminal closes, use nohup and optionally run the job in the background.

Example – export all MySQL databases while logging output:

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

If you prefer not to expose the password on the command line, omit the trailing & and enter the password when prompted, then suspend with Ctrl+Z and resume in the background using bg.

The command creates a nohup.out file in the current directory containing any error messages.

3. Find Processes with High Memory Usage

Identify memory‑hungry processes and sort them: ps -aux | sort -rnk 4 | head -20 The fourth column shows the memory usage percentage; the last column shows the corresponding process.

4. Find Processes with High CPU Usage

Similarly, sort processes by CPU consumption: ps -aux | sort -rnk 3 | head -20 The third column displays the CPU usage percentage.

5. View Multiple Logs Simultaneously

Instead of opening separate terminals for each log, install multitail to monitor several files in one view.

Installation:

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.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 and Log Results

Record ping output with timestamps to a log file, useful for troubleshooting network issues:

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

The log receives one entry per second.

7. View TCP Connection States

Check the state of TCP connections on port 80, helpful for analyzing connection releases or attacks:

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

8. Find Top 20 IPs Requesting Port 80

Identify the IP addresses generating the most requests on 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

Use SSH to forward a local port to a remote server without exposing the remote service directly.

Example – forward local port 9200 to 192.168.1.19:9200 via a bastion host 192.168.1.15:

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

After execution, accessing 192.168.1.15:9200 actually reaches 192.168.1.19:9200.

Follow‑up

This concludes the current collection; further notes will be added later.

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.

SSHxargsnohupmultitail
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.