Essential Linux & Server Commands: From Log Cleanup to RAID and Monitoring
This guide presents practical Linux and server administration commands, covering log cleanup, nginx IP analysis, tcpdump capture, Python date formatting and string reversal, subprocess execution, multiprocessing, iptables port forwarding, cron scheduling, file relocation, RAID concepts, Oracle backup strategies, port checking, Apache MPM modes, and monitoring tool comparisons.
1. Delete *.log files older than three days
Use find . -ctime +3 -name '*.log' | xargs rm -rf (or directly find . -ctime +3 -name '*.log' -exec rm -rf {} +).
2. Find top 10 IPs by page requests in nginx access log
Command:
cat access.log | awk '{print $1}' | uniq -c | sort -rn | head -103. Capture HTTP traffic from 192.168.1.1 port 80 with tcpdump
Command:
tcpdump 'host 192.168.1.1 and port 80' > tcpdump.log4. Print yesterday’s local time in Python
Example:
import time; print(time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(time.time() - 86400)))5. Reverse a numeric string in Python
Use slicing: '123456'[::-1] yields '654321'.
6. Execute shell commands from Python and capture output
Example using subprocess:
import subprocess
proc = subprocess.Popen('ls', shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = proc.communicate()
print(stdout)7. Parallel execution class with multiprocessing
Example:
import multiprocessing, time
class ClockProcess(multiprocessing.Process):
def __init__(self, interval):
super().__init__()
self.interval = interval
def run(self):
n = 5
while n > 0:
print("the time is {0}".format(time.ctime()))
time.sleep(self.interval)
n -= 18. Forward local port 80 to 8080 on host 192.168.2.1
iptables command:
iptables -t nat -A PREROUTING -d 192.168.2.1 -p tcp --dport 80 -j REDIRECT --to-port 80809. Schedule a cron job to run every 2 hours between 6 am and 12 pm in November
Cron expression:
0 6-12/2 * 11 * /usr/bin/httpd.sh10. Move files larger than 100 KB from /usr/local/test to /tmp
Command:
find /usr/local/test -type f -size +100k -exec mv {} /tmp/ \;Alternative script example provided.
11. RAID levels 0, 1, and 5 overview
RAID 0 : Striping for performance, no redundancy.
RAID 1 : Mirroring for redundancy, read performance boost, 50% usable capacity.
RAID 5 : Distributed parity across at least three disks, provides redundancy and improved read/write performance.
12. Oracle database backup methods
Physical backup (cold/hot) using RMAN; logical backup of tables, schemas via exp/expdp or flashback.
Backup strategies: full, incremental, differential.
13. Identify process using port 8080
Commands: netstat -anpt | grep 8080 or
lsof -i :808014. Apache 2.x MPM modes and module inspection
prefork : Multi‑process, one thread per process, higher memory usage, good isolation.
worker : Multi‑process with multiple threads per process, lower memory, better concurrency.
List loaded modules: httpd -M or httpd -l. Show compile‑time settings: httpd -V.
15. Monitoring tools comparison
Nagios – status monitoring via NRPE, SNMP, alerts via SMS/email.
Cacti – performance and traffic graphs via SNMP.
Zabbix – open‑source, combines features of Nagios and Cacti, supports auto‑discovery, distributed monitoring, multiple protocols.
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.
MaGe Linux Operations
Founded in 2009, MaGe Education is a top Chinese high‑end IT training brand. Its graduates earn 12K+ RMB salaries, and the school has trained tens of thousands of students. It offers high‑pay courses in Linux cloud operations, Python full‑stack, automation, data analysis, AI, and Go high‑concurrency architecture. Thanks to quality courses and a solid reputation, it has talent partnerships with numerous internet firms.
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.
