Operations 8 min read

20 Essential Linux Command-Line Tricks Every Sysadmin Should Know

A concise collection of practical Linux shell commands covers file clearing, log analysis, bulk file creation, mass file operations, advanced find usages, history shortcuts, sed editing tricks, network interface filtering, and more, providing sysadmins with ready-to-use shortcuts for daily tasks.

Liangxu Linux
Liangxu Linux
Liangxu Linux
20 Essential Linux Command-Line Tricks Every Sysadmin Should Know

Linux Knowledge Pocket

This article gathers a set of handy Linux command‑line tricks that can speed up everyday system administration work.

1. Quickly empty a file

cat /dev/null > haodao.txt

2. Count unique IP addresses in a Tomcat access log

awk '{print $1}' access.log | sort | uniq | wc -l

3. Generate a large test file

Use dd to create a file of a specific size for disk‑read/write testing. dd if=/dev/zero of=test.txt bs=1M count=1000 The command above creates test.txt with a size of 1 GB.

4. Create many files with similar names

touch haodao{1..100}.txt

5. Find and delete all .txt files in the current directory

find . -name "*.txt" -exec rm -rf {} \;

Alternative forms:

find . -name "*.txt" | xargs rm -rf
rm -rf $(find . -name "*.txt")

6. Delete .txt files older than 7 days

find . -mtime +7 -name "*.txt" | xargs rm -rf

7. Move files larger than 1000 M to /root/home

find . -size +1000M -exec mv {} /root/home \;

8. Delete .txt files older than 30 days and larger than 1000 M

find . -name "*.txt" -mtime +30 -type f -size +1000M | xargs rm -rf

9. Show the 10 most frequently used commands from history

cat /root/.bash_history | grep -v ^# | awk '{print $1}' | sort | uniq -c | sort -nr | head -10

10. Count IP accesses to Tomcat on a specific date and hour (e.g., 2021‑12‑11 09:00)

awk '{print $4,$1}' access.log | grep '11/Dec/2021:09' | awk '{print $2}' | sort | uniq | wc -l

Providing the log file allows the calculation; the same method works for any timestamp.

11. List the top 10 IP addresses by request count

cat access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -10

12. Count how many times a specific page was accessed

grep "/portal/index.html" access.log | wc -l

13. Show which pages a particular IP accessed

grep ^192.168.20.100 access.log | awk '{print $1,$7}'

14. Use tcpdump to inspect traffic on port 8080

tcpdump -i ens120 -tnn dst port 8080 -c 1000 | awk -F "." '{print $1"."$2"."$3"."$4}' | sort | uniq -c | sort -nr | head -10

15. History command shortcuts

!!

– repeat the previous command. !N – repeat command number N from history. !awk – repeat the most recent command starting with awk. !$ – use the last argument of the previous command.

Example: mv !$ !$ .bak renames test.txt to test.txt.bak.

16. Replace all occurrences of "haodao" with "HAODAO" in test.txt

sed -i "s/haodao/HAODAO/g" test.txt

17. Replace a directory path in haodao.txt

sed -i "s:/etc/dhcp:/home:g" haodao.txt

18. Common sed tricks on haodao.txt

Remove leading # characters: sed -i "s/^#//g" haodao.txt Add the word linux at the beginning of each line: sed -i "s/^/linux/g" haodao.txt Append study at the end of each line: sed -i "s/$/study/" haodao.txt After a line containing we love, insert you: sed -i "/we love/a you" haodao.txt Before a line containing haodao, insert where:

sed -i "/haodao/i where" haodao.txt

19. List network interfaces that are up

ip addr | awk -F ':' '/state UP/ {print $2}'

20. Show IP addresses and their corresponding interfaces

ip -o addr | awk '/inet/ {print $2,$4}'

Conclusion

The commands above are simple yet powerful tricks that many developers overlook; mastering them can greatly improve daily productivity.

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.

LinuxShellTips
Liangxu Linux
Written by

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

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.