Skip to main content

45 Efficient Linux Command Combinations for Developers and Sysadmins

·821 words·4 mins
Linux Command Linux Tips Sysadmin DevOps
Table of Contents

Mastering the Linux command line is essential for developers, system administrators, and DevOps engineers. This guide collects 45 efficient Linux command combinations that cover file management, process monitoring, networking, and system optimization. These commands can help you save time, troubleshoot issues faster, and improve your workflow.


1. Quickly Create Multiple Files
#

touch pudn{1..100}.py

Creates files pudn1.py through pudn100.py.


2. Generate a Large File for Disk Testing
#

dd if=/dev/zero of=/root/pudnlinux/test.txt bs=1M count=1024

Generates a 1GB test file in /root/pudnlinux, useful for I/O and disk performance tests.


3. Efficient Ways to Empty a File
#

cat /dev/null > pudn.py
echo -n "" > pudn.py
true > pudn.py
: > pudn.py
truncate -s 0 pudn.py

4–12. Find and Delete Files with find
#

  • Find a specific file:

    find . -name pudn.py
    
  • Find all .py files:

    find . -name "*.py"
    
  • Restrict search to files only:

    find . -type f -name "*.py"
    
  • Find directories starting with “pudn”:

    find . -type d -name "pudn*"
    
  • Search by permissions:

    find . -type f -perm 755
    find . -type f ! -perm 755
    find . -type f -perm 777 -exec chmod 755 {} \;
    
  • Search by file size:

    find . -type f -size +100M -size -1G
    
  • Delete .py files:

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

13–20. Search Files by Time and Size
#

  • Files modified 30 days ago:

    find . -mtime 30
    
  • Files accessed 30 days ago:

    find . -atime 30
    
  • Files modified within 1 hour:

    find . -mmin -60
    
  • Files accessed within 1 hour:

    find . -amin -60
    
  • Files modified between 10 and 30 days ago:

    find . -mtime +10 -mtime -30
    
  • Delete .py files older than 7 days:

    find . -mtime +7 -name "*.py" | xargs rm -rf
    
  • Move files larger than 1000M:

    find . -size +1000M -exec mv {} /root/home \;
    
  • Delete .py files >1000M and older than 30 days:

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

21–22. Check CPU Information
#

  • Show logical CPUs and models:

    cat /proc/cpuinfo | grep name | cut -f2 -d: | uniq -c
    
  • Show physical CPUs and cores:

    cat /proc/cpuinfo | grep physical | uniq -c
    

23. Run Commands in the Background
#

nohup ping www.baidu.com &
nohup ping www.baidu.com > /dev/null &
nohup ping www.baidu.com >out.log 2>&1 &

Keeps processes running even after logging out.


24–28. Process and Directory Management
#

  • Kill processes containing a keyword:

    ps aux | grep xxx | grep -v grep | awk '{print $2}' | xargs kill -9
    
  • Sort /var by size:

    du -xB M --max-depth=2 /var | sort -rn | head -n 20
    
  • Largest 10 directories or files:

    du -s * | sort -n | tail
    
  • Top 20 memory-consuming processes:

    ps -aux | sort -rnk 4 | head -20
    
  • Top 20 CPU-consuming processes:

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

29. Continuous Ping with Timestamp Logging
#

ping www.baidu.com | awk '{ print $0 " " strftime("%Y-%m-%d %H:%M:%S",systime()) }' >> /root/pudnping.log &

30–36. Networking and Access Logs
#

  • Top 15 IPs accessing port 80:

    netstat -anlp|grep 80|grep tcp|awk '{print $5}' |awk -F: '{print $1}'|sort|uniq -c|sort -nr|head -n 15
    
  • Most used commands:

    cat /root/.bash_history | awk '{print $1}' | sort | uniq -c | sort -nr | head -10
    
  • Count unique IPs at a specific time:

    awk '{print $4,$1}' access.log | grep 11/Dec/2022:09 | awk '{print $2}'| sort | uniq | wc -l
    
  • Top 20 visiting IPs:

    cat access.log | awk '{print $1}' | sort | uniq -c | sort -nr | head -20
    
  • Resources accessed by a specific IP:

    grep ^192.168.30.200 access.log| awk '{print $1,$7}'
    
  • Count page visits:

    grep "/portal/index.html" access.log | wc -l
    
  • Capture 8080 port traffic:

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

37–39. File Editing with sed
#

  • Replace text:

    sed -i "s/pudn/pudn/g" test.py
    
  • Replace directory path:

    sed -i "s:/etc/dhcp:/home:g" pudn.py
    
  • Remove # from line start:

    sed -i "s/^#//g" pudn.py
    
  • Add text to line start/end:

    sed -i "s/^/linux/g" pudn.py
    sed -i "s/$/study/" pudn.py
    
  • Insert text before/after a line:

    sed -i "/we love/ayou" pudn.py
    sed -i "/pudn/iwhere" pudn.py
    

40–45. Packet Capture with tcpdump
#

  • Save packets to a file:

    tcpdump -i ens33 -s 0 -w pudn.cap
    
  • Capture ICMP from a specific source:

    tcpdump icmp and src 192.168.20.231 -i ens33 -n
    
  • Capture packets from source host:

    tcpdump src host 192.168.20.231 -i ens33 -n -c 5
    
  • Capture packets to destination host:

    tcpdump dst host 192.168.20.231 -i ens33 -n -c 5
    
  • Capture port 8080 traffic:

    tcpdump port 8080 -i ens33 -n -c 5
    
  • Capture traffic between port 80 and 443:

    tcpdump portrange 80-433 -i ens33 -n -c 8
    

Final Thoughts
#

These 45 Linux command combinations cover everything from file manipulation and system monitoring to networking and security analysis. Whether you’re a Linux beginner, an experienced sysadmin, or working in DevOps, these practical examples will help you manage systems more efficiently and troubleshoot problems faster.

Related

600 Essential Linux Commands for Developers and Sysadmins
·1004 words·5 mins
Linux Linux Commands Sysadmin DevOps Server Management
20 Essential Docker Container Script Commands
·650 words·4 mins
Docker Script DevOps Automation
How to Check if Linux Is Running on a Virtual Machine or Physical Machine
·381 words·2 mins
Linux Virtualization System Administration SSH