17 Essential Linux Sysadmin Commands to Boost Productivity
This article compiles 17 practical Linux operation tricks—from file searching and batch extraction to disk monitoring, log analysis, and firewall scripting—providing sysadmins with ready-to-use command snippets that can streamline daily tasks and potentially earn a raise.
Overview
The following collection presents seventeen frequently used Linux command‑line techniques that address common administrative tasks such as file management, text processing, system monitoring, and security configuration.
1. Move all *.tar files to a backup directory
find . -name "*.tar" -exec mv {} ./backup/ ;2. Batch unzip all *.zip files to a target directory
for i in `find . -name "*.zip" -type f`; do
unzip -d $i /data/www/img/
done3. Common sed operations (example file: test.txt)
Remove the first character of each line: sed -i 's/^./ /' test.txt Delete the leading dot: sed -i 's/^\.//' test.txt Prepend an a to each line: sed -i 's/^/a/' test.txt Append an a to each line: sed -i 's/$/a/' test.txt Insert c after a matching pattern: sed -i '/wuguangke/a c' test.txt Replace a pattern globally:
sed -i 's:/user/local:/tmp:g' test.txt4. Test for a directory and create it if missing
if [ ! -d /data/backup/ ]; then
mkdir -p /data/backup/
else
echo "The Directory already exists, please exit"
fi5. Monitor root partition usage and email when ≥90%
# Print usage percentage
df -h | sed -n '/\//p' | awk '{print $5}' | awk -F'%' '{print $1}'
# Loop and send alert
while sleep 5m; do
for i in `df -h | sed -n '/\//p' | awk '{print $5}' | sed 's/%//g'`; do
if [ $i -ge 90 ]; then
echo "More than 90% Linux disk space, please check!" | mail -s "Warn Linux Disk $i%" [email protected]
fi
done
done6. List top 20 IPs from Nginx access log
cat access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -207. Change SELinux mode to disabled
sed -i '/SELINUX/s/enforcing/disabled/' /etc/selinux/config8. Print maximum and minimum values from a file
# Max value
cat a.txt | sort -nr | awk 'NR==1{print}'
# Min value
cat a.txt | sort -n | awk 'NR==1{print}'
# One‑liner using sed and sort
sed 's/ / /g' a.txt | sort -nr | sed -n '1p;$p'9. Retrieve SNMP v2c data (example host)
snmpwalk -v2c -c public 192.168.0.24110. Replace lines ending with jk by yz
sed -e 's/jk$/yz/g' b.txt11. Basic tcpdump captures
# Capture traffic to 192.168.56.7 on port 80
tcpdump -nn host 192.168.56.7 and port 80
# Exclude host 192.168.0.22 on port 80
tcpdump -nn host 192.168.56.7 or ! host 192.168.0.22 and port 8012. Show the 20 most frequently used commands
cat .bash_history | grep -v '^#' | awk '{print $1}' | sort | uniq -c | sort -nr | head -2013. Delete *.log files older than 3 days
find . -mtime +3 -name "*.log" | xargs rm -rf {} ;14. Move files larger than 100 KB to /tmp
find . -size +100k -exec mv {} /tmp ;15. Simple firewall allowing only remote access to port 80
iptables -F
iptables -X
iptables -A INPUT -p tcp --dport 80 -j ACCEPT
iptables -A INPUT -p tcp -j REJECT16. Nginx log analysis – top 10 IPs
cd /home/logs/nginx/default
sort -m -k4 -o access.logok access.1 access.2 access.3 ...
cat access.logok | awk '{print $1}' | sort -n | uniq -c | sort -nr | head -1017. Replace directory paths in a file
sed -i 's:/user/local:/tmp:g' test.txtThese snippets provide a quick reference for everyday Linux administration, helping engineers automate routine tasks, monitor system health, and enforce basic security policies.
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.
Liangxu Linux
Liangxu, a self‑taught IT professional now working as a Linux development engineer at a Fortune 500 multinational, shares extensive Linux knowledge—fundamentals, applications, tools, plus Git, databases, Raspberry Pi, etc. (Reply “Linux” to receive essential resources.)
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.
