Essential Linux Commands Every Server Engineer Should Know

Today, we will discuss the essential Linux commands that every server engineer must master, along with the fundamental principles behind them.

1. System Monitoring and Diagnostic Commands: Your “Stethoscope”

1. top/htop – The “Real-time Monitor” of System Status

# Basic Usage
top                    # Real-time display of system processes
htop                   # A more user-friendly alternative to top, requires installation yum install htop

# Useful Parameters
top -p 1234           # Monitor a specific process only
top -u username       # Show processes for a specific user
top -d 2              # Refresh every 2 seconds

Real-world Scenario: When the system becomes unresponsive, <span>top</span> can help you quickly identify which process is causing the issue.

# View the processes with the highest CPU usage
top -o %CPU

# View the processes with the highest memory usage
top -o %MEM

Fundamental Principle: <span>top</span> retrieves real-time data by reading the <span>/proc</span> filesystem, which is the standard interface for the Linux kernel to expose system information.

2. iostat – The “X-ray” of IO Performance

# Install sysstat package
yum install sysstat    # CentOS/RHEL
apt install sysstat    # Ubuntu/Debian

# Basic Usage
iostat                # Display CPU and IO statistics
iostat -x 1 5         # Display extended statistics every 1 second, 5 times
iostat -d 2           # Display disk statistics every 2 seconds

Real-world Scenario: When database queries slow down, suspecting a disk IO bottleneck.

# Monitor disk IO, focusing on await and util%
iostat -x 1
# await: average wait time, util%: disk utilization

3. netstat/ss – The “Map” of Network Connections

# netstat usage
netstat -tulpn         # Show all TCP/UDP connections and listening ports
netstat -an | grep :80 # View connections on port 80
netstat -rn            # Display routing table

# ss usage (recommended, faster)
ss -tulpn              # Show all connections
ss -tulpn | grep :3306 # View MySQL connections
ss -s                  # Show connection statistics

Real-world Scenario: When an application reports “port is occupied”, you need to find the occupying process.

# Find the process occupying port 8080
ss -tulpn | grep :8080
# or
netstat -tulpn | grep :8080

4. df/du – The “Manager” of Disk Space

# df - File system usage

df -h                  # Human-readable format
df -i                  # Show inode usage

# du - Directory size
du -sh /var/log        # View the size of the log directory
du -sh *               # View the size of each file/directory in the current directory
du -h --max-depth=1    # Show only the size of first-level subdirectories

Real-world Scenario: When disk space is insufficient, you need to clean up large files.

# Find the largest directories
du -h --max-depth=1 /var | sort -hr

# Find the largest files
find /var -type f -exec du -h {} + | sort -hr | head -10

5. free – The “Barometer” of Memory Usage

free -h                # Human-readable format
free -m                # In MB
free -s 5              # Refresh every 5 seconds

Real-world Scenario: When an application encounters OOM (Out of Memory), you need to analyze memory usage.

# View detailed memory usage
free -h
# Focus on the available field, which indicates truly available memory

6. ps – The “File Manager” of Process Information

# Common combinations
ps aux                 # Show all processes
ps -ef                 # Another format
ps aux | grep nginx    # Find nginx process
ps -o pid,ppid,cmd,%mem,%cpu --sort=-%mem  # Sort by memory usage

Real-world Scenario: When a Java application has a memory leak, you need to find the specific process.

# Find Java processes and sort by memory usage
ps aux | grep java | sort -k4 -nr

7. lsof – The “Detective” of File/Port Usage

lsof -i :8080          # View who is using port 8080
lsof -p 1234           # View files opened by process 1234
lsof /var/log/app.log  # View who is using this file
lsof +D /tmp           # View files opened in the /tmp directory

Real-world Scenario: When deleting a file, you receive a message that “the file is in use”.

# Find the process using the file
lsof /path/to/file
# Then kill the related process or restart the service

2. File and Directory Operation Commands: Your “File Manager”

1. find – The “Search Engine” for File Searching

# Basic Usage
find /var -name "*.log"                    # Search by name
find /home -type f -size +100M             # Find files larger than 100M
find /tmp -type d -empty                   # Find empty directories
find /var -mtime +7 -name "*.log"          # Find log files older than 7 days

# Advanced Usage
find /var -name "*.log" -exec rm {} \;     # Delete found files
find /var -name "*.log" -exec ls -lh {} \; # Execute command on found files

Real-world Scenario: Clean up expired log files.

# Delete log files older than 30 days
find /var/log -name "*.log" -mtime +30 -delete

2. grep – The “Hound” of Text Searching

# Basic Usage
grep "error" /var/log/app.log              # Search for lines containing error
grep -i "error" /var/log/app.log           # Ignore case
grep -n "error" /var/log/app.log           # Show line numbers
grep -r "error" /var/log/                  # Recursive search

# Advanced Usage
grep -E "error|warning" /var/log/app.log   # Regular expression
grep -A 3 -B 3 "error" /var/log/app.log   # Show 3 lines before and after matching line
grep -v "debug" /var/log/app.log           # Exclude lines containing debug

Real-world Scenario: Quickly locate errors in a large number of logs.

# Find the most recent error logs
tail -1000 /var/log/app.log | grep -i error

3. awk – The “Swiss Army Knife” of Text Processing

# Basic Usage
awk '{print $1}' /var/log/access.log       # Print the first column
awk -F: '{print $1}' /etc/passwd           # Print the first column separated by colon
awk '$3 > 1000 {print $0}' /etc/passwd     # Print lines where the third column is greater than 1000

# Advanced Usage
awk '{sum+=$1} END {print sum}' numbers.txt # Sum
awk 'NR==1 {print "Header"}; NR>1 {print $0}' file.txt # Add header

Real-world Scenario: Analyze Nginx access logs to count IP access times.

# Count the most accessed IPs
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head -10

4. sed – The “Magician” of Text Editing

# Basic Usage
sed 's/old/new/g' file.txt                 # Replace all old with new
sed 's/old/new/' file.txt                  # Replace only the first old
sed '1d' file.txt                          # Delete the first line
sed '1,5d' file.txt                        # Delete lines 1-5

# Advanced Usage
sed -i 's/old/new/g' file.txt              # Modify file directly
sed '/pattern/d' file.txt                  # Delete lines containing pattern
sed 's/^/# /' file.txt                     # Add comment symbol at the beginning of each line

Real-world Scenario: Batch modify configuration files.

# Change localhost to actual IP in configuration file
sed -i 's/localhost/192.168.1.100/g' /etc/nginx/nginx.conf

5. tar – The “Packager” for Compression and Decompression

# Compression
tar -czf backup.tar.gz /var/log/           # Compress directory
tar -czf backup.tar.gz file1 file2         # Compress multiple files

# Decompression
tar -xzf backup.tar.gz                     # Decompress to current directory
tar -xzf backup.tar.gz -C /tmp/            # Decompress to specified directory

# View contents of compressed file
tar -tzf backup.tar.gz                     # List contents of compressed file

Real-world Scenario: Backup important data.

# Backup website data
tar -czf website_backup_$(date +%Y%m%d).tar.gz /var/www/html/

6. rsync – The “Courier” for File Synchronization

# Basic Usage
rsync -av /source/ /destination/           # Synchronize directory
rsync -av --delete /source/ /destination/  # Synchronize and delete extra files in the destination
rsync -avz /source/ user@host:/destination/ # Compress and transfer to remote

# Advanced Usage
rsync -av --exclude='*.log' /source/ /destination/ # Exclude log files
rsync -av --progress /source/ /destination/        # Show progress

Real-world Scenario: Deploy applications to multiple servers.

# Synchronize application code to production server
rsync -avz --exclude='.git' /app/ user@prod-server:/var/www/app/

3. Network Related Commands: Your “Network Diagnostician”

1. curl/wget – The “Tester” for HTTP Requests

# curl usage
curl cip.cc                  # Simple GET request, get server's external IP
curl -X POST -d "data=value" http://api.com # POST request
curl -H "Authorization: Bearer token" http://api.com # With authorization header
curl -o file.html http://example.com       # Save to file
curl -I http://example.com                 # Only get response headers

# wget usage
wget http://example.com/file.zip           # Download file
wget -O filename.zip http://example.com/file.zip # Specify save filename
wget -r http://example.com/                # Recursive download

Real-world Scenario: Test if the API interface is functioning properly.

# Test health check interface
curl -f http://localhost:8080/health || echo "Service is down"

2. ping/traceroute – The “Pathfinder” for Network Connectivity

# ping usage
ping google.com                            # Test connectivity
ping -c 4 google.com                       # Send 4 packets
ping -i 2 google.com                       # Send one packet every 2 seconds

# traceroute usage
traceroute google.com                      # Trace route
traceroute -n google.com                   # Do not resolve hostnames

Real-world Scenario: Troubleshoot network connection issues.

# Test connectivity to database server
ping -c 3 db-server
traceroute db-server

3. tcpdump – The “Listener” for Network Packet Capture

# Basic Usage
tcpdump -i eth0                            # Listen on eth0 network card
tcpdump port 80                            # Listen on port 80
tcpdump host 192.168.1.100                 # Listen to a specific host
tcpdump -w capture.pcap                    # Save to file

# Advanced Usage
tcpdump -i any -n port 3306                # Listen to MySQL traffic
tcpdump -i any -n 'tcp port 80 and host 192.168.1.100' # Combined conditions

Real-world Scenario: Analyze network communication issues.

# Capture HTTP requests
tcpdump -i any -A -s 0 'tcp port 80 and (((ip[2:2] - ((ip[0]&amp;0xf)&lt;&lt;2)) - ((tcp[12]&amp;0xf0)&gt;&gt;2)) != 0)'

4. nmap – The “Scout” for Port Scanning

# Basic Usage
nmap 192.168.1.1                          # Scan host
nmap -p 80,443 192.168.1.1                # Scan specific ports
nmap -p 1-1000 192.168.1.1                # Scan port range
nmap -sS 192.168.1.1                      # SYN scan

# Advanced Usage
nmap -O 192.168.1.1                       # Operating system detection
nmap -sV 192.168.1.1                      # Service version detection
nmap -A 192.168.1.1                       # Comprehensive scan

Real-world Scenario: Security audit, check open ports.

# Scan internal network server for open services
nmap -sS -O 192.168.1.0/24

5. ssh – The “Architect” of Secure Channels

SSH tunneling is a core skill in secure development, as it not only establishes secure remote connections but also creates various types of tunnels to bypass network restrictions.

# Basic Connection
ssh user@hostname                          # Basic SSH connection
ssh -p 2222 user@hostname                  # Connect using specified port
ssh -i ~/.ssh/id_rsa user@hostname         # Connect using key file

# Local Port Forwarding
ssh -L 8080:localhost:80 user@jumpserver   # Forward local port 8080 to jumpserver's port 80
ssh -L 3306:db-server:3306 user@jumpserver # Access database through jump server

# Remote Port Forwarding
ssh -R 8080:localhost:80 user@remote-server # Forward remote server's port 8080 to local port 80
ssh -R 0.0.0.0:8080:localhost:80 user@remote-server # Allow external access to forwarded port

# Dynamic Port Forwarding (SOCKS Proxy)
ssh -D 1080 user@jumpserver                # Create SOCKS5 proxy, listening on local port 1080
ssh -D 0.0.0.0:1080 user@jumpserver       # Allow other machines to use the proxy

# Combined Usage
ssh -L 8080:localhost:80 -L 3306:db:3306 -D 1080 user@jumpserver

# Background Running Parameter Combination -fNg (Important!)
ssh -fNg -L 8080:localhost:80 user@jumpserver    # Run local port forwarding in the background
ssh -fNg -R 8080:localhost:80 user@remote-server # Run remote port forwarding in the background
ssh -fNg -D 1080 user@jumpserver                 # Run SOCKS proxy in the background

SSH Tunnel Background Running Parameter Explanation:

# -f: Run in the background (fork to background)
# -N: Do not execute remote commands (only establish tunnel, do not open shell)
# -g: Allow remote hosts to connect to local forwarded ports (GatewayPorts)

# Practical Application Example
ssh -fNg -L 3306:db-server:3306 user@jumpserver
# This command will:
# 1. Run in the background (-f)
# 2. Only establish the tunnel, do not open shell (-N)
# 3. Allow other machines to connect to local port 3306 through jumpserver (-g)
# 4. Forward local port 3306 to db-server:3306

# View background SSH processes
ps aux | grep ssh
# or
pgrep -f "ssh.*-L.*3306"

# Close background SSH tunnel
kill $(pgrep -f "ssh.*-L.*3306")

Real-world Scenario 1: Access internal database through jump server.

# Method 1: Run in foreground (will occupy terminal)
ssh -L 3306:192.168.1.100:3306 user@jumpserver
# Then you can connect to the database locally using mysql -h 127.0.0.1 -P 3306

# Method 2: Run in background (recommended, does not occupy terminal)
ssh -fNg -L 3306:192.168.1.100:3306 user@jumpserver
# The tunnel runs in the background, and the terminal can continue to be used
# Remember to close it after use: kill $(pgrep -f "ssh.*-L.*3306")

Real-world Scenario 2: Establish SOCKS proxy to access internal services.

# Method 1: Run SOCKS proxy in foreground
ssh -D 1080 user@jumpserver
# Configure the browser to use 127.0.0.1:1080 as SOCKS proxy

# Method 2: Run SOCKS proxy in background (recommended)
ssh -fNg -D 1080 user@jumpserver
# The proxy runs in the background, allowing the terminal to continue being used

# Use curl to access internal API through proxy
curl --socks5 127.0.0.1:1080 http://internal-api.company.com/api/data

# Close background SOCKS proxy
kill $(pgrep -f "ssh.*-D.*1080")

Real-world Scenario 3: Reverse tunnel to provide external access to internal services.

# Method 1: Run reverse tunnel in foreground
ssh -R 8080:localhost:8080 user@public-server
# External users can access internal services through public-server:8080

# Method 2: Run reverse tunnel in background (recommended)
ssh -fNg -R 8080:localhost:8080 user@public-server
# The tunnel runs in the background, continuously providing external access to internal services

# Method 3: Allow external access to reverse tunnel
ssh -fNg -R 0.0.0.0:8080:localhost:8080 user@public-server
# 0.0.0.0 means allowing any IP to access the forwarded port

# Close background reverse tunnel
kill $(pgrep -f "ssh.*-R.*8080")

Best Security Practices:

# Use key authentication instead of password
ssh-keygen -t rsa -b 4096 -C "[email protected]"
ssh-copy-id user@hostname

# Configure SSH client
cat ~/.ssh/config
Host jumpserver
    HostName 192.168.1.10
    User root
    Port 22
    IdentityFile ~/.ssh/id_rsa
    LocalForward 3306 localhost:3306
    LocalForward 8080 localhost:8080

# Connect using configuration
ssh jumpserver

Fundamental Principle: SSH tunneling essentially establishes a virtual network connection over an SSH connection, transmitting data through an encrypted SSH channel, achieving:

  • Security: All data is encrypted via SSH
  • Transparency: Applications can use the tunnel without modification
  • Flexibility: Supports various forwarding modes to adapt to different scenarios

6. scp – The “Courier” for Secure File Transfer

<span>scp</span> (Secure Copy) is a secure file transfer tool based on the SSH protocol, an essential skill for server engineers for file deployment and backup.

# Basic Syntax
scp [options] source_file destination_location

# Local to Remote
scp file.txt user@hostname:/remote/path/           # Upload file
scp -r /local/dir/ user@hostname:/remote/path/     # Upload directory
scp file.txt user@hostname:~/                      # Upload to user home directory

# Remote to Local
scp user@hostname:/remote/file.txt /local/path/    # Download file
scp -r user@hostname:/remote/dir/ /local/path/     # Download directory
scp user@hostname:~/file.txt ./                    # Download to current directory

# Remote to Remote
scp user1@host1:/path/file.txt user2@host2:/path/  # Transfer between servers

# Common Parameters
scp -P 2222 file.txt user@hostname:/path/          # Specify port
scp -i ~/.ssh/id_rsa file.txt user@hostname:/path/ # Use key file
scp -C file.txt user@hostname:/path/               # Enable compression during transfer
scp -v file.txt user@hostname:/path/               # Show detailed transfer information
scp -p file.txt user@hostname:/path/               # Preserve file attributes (timestamps, permissions)

Real-world Scenario 1: Deploy application files to production server.

# Upload application package to production server
scp -P 2222 -i ~/.ssh/prod_key app.tar.gz deploy@prod-server:/opt/apps/

# Upload configuration file
scp -P 2222 -i ~/.ssh/prod_key config/nginx.conf deploy@prod-server:/etc/nginx/

# Batch upload multiple files
scp -P 2222 -i ~/.ssh/prod_key *.jar deploy@prod-server:/opt/apps/

Real-world Scenario 2: Backup important data.

# Backup database files
scp -C -p db-backup.sql admin@backup-server:/backup/$(date +%Y%m%d)/

# Backup entire application directory
scp -r -C -p /var/www/html/ admin@backup-server:/backup/website/

# Backup log files
scp -C /var/log/app/*.log admin@backup-server:/backup/logs/

Real-world Scenario 3: Data synchronization between servers.

# Synchronize data from master server to backup server
scp -r -C -p user@master-server:/data/ user@backup-server:/data/

# Synchronize configuration files
scp -p user@config-server:/etc/nginx/nginx.conf user@web-server:/etc/nginx/

Advanced Usage and Tips:

# Use wildcards for batch transfer
scp user@server:/var/log/*.log ./logs/

# Show progress during transfer (requires pv)
scp -C file.tar.gz user@server:/tmp/ | pv -l

# Transfer files through jump server
scp -o ProxyCommand="ssh -W %h:%p user@jumpserver" file.txt user@target-server:/path/

# Use compression for large file transfers
scp -C -l 1000 large-file.iso user@server:/tmp/
# -l 1000 limits transfer speed to 1000Kbps

scp vs rsync Comparison:

# scp: Simple and direct, suitable for one-time transfers
scp -r /source/ user@server:/destination/

# rsync: Incremental synchronization, suitable for regular backups
rsync -avz --delete /source/ user@server:/destination/
# rsync advantages: only transfers changed parts, supports resuming interrupted transfers

Best Security Practices:

# 1. Use key authentication
scp -i ~/.ssh/id_rsa file.txt user@server:/path/

# 2. Specify port (avoid using default port 22)
scp -P 2222 file.txt user@server:/path/

# 3. Enable compression and limit speed when transferring sensitive files
scp -C -l 500 sensitive-data.tar.gz user@server:/secure/

# 4. Use scripts for batch transfers
#!/bin/bash
for file in *.log; do
    scp -C -p "$file" user@server:/backup/logs/
done

Fundamental Principle: <span>scp</span> is based on the SSH protocol, inheriting all security features of SSH:

  • Encrypted Transfer: All data is encrypted via SSH
  • Authentication: Supports both password and key authentication methods
  • Integrity Check: Ensures data is not tampered with during transfer
  • Simple and Easy to Use: Simple syntax, low learning cost

4. Process and Service Management Commands: Your “System Administrator”

1. systemctl – The “Commander” of Service Management

# Basic Usage
systemctl start nginx                      # Start service
systemctl stop nginx                       # Stop service
systemctl restart nginx                    # Restart service
systemctl reload nginx                     # Reload configuration
systemctl status nginx                     # View service status
systemctl enable nginx                     # Set to start on boot
systemctl disable nginx                    # Cancel start on boot

# Advanced Usage
systemctl list-units --type=service        # List all services
systemctl list-unit-files --type=service   # List all service files
systemctl daemon-reload                    # Reload systemd configuration

Real-world Scenario: Deploy new version of application.

# Gracefully restart application service
systemctl reload app-service
# If reload is not supported, then
systemctl restart app-service

2. kill/killall – The “Terminator” of Process Control

# kill usage
kill 1234                                  # Send TERM signal
kill -9 1234                              # Send KILL signal (force kill)
kill -HUP 1234                            # Send HUP signal (reload configuration)

# killall usage
killall nginx                              # Kill all nginx processes
killall -9 java                            # Force kill all java processes
killall -u username                        # Kill all processes of a user

Real-world Scenario: When an application is unresponsive, you need to force restart it.

# Gracefully stop application
kill -TERM $(pgrep -f "java.*app")
# Wait 5 seconds and then force kill
sleep 5 && kill -KILL $(pgrep -f "java.*app")

3. nohup – The “Guardian” of Background Running

# Basic Usage
nohup java -jar app.jar &                  # Run Java application in background
nohup python script.py > output.log 2>&1 & # Run Python script in background and redirect output

# View background tasks
jobs                                       # View current shell's background tasks
fg %1                                      # Bring background task to foreground
bg %1                                      # Send paused task to background

Real-world Scenario: Run long-term tasks on the server.

# Run data migration script
nohup python migrate_data.py > migrate.log 2>&1 &
echo $! > migrate.pid  # Save process ID

4. screen/tmux – The “Jack of All Trades” of Session Management

# screen usage
screen -S session_name                     # Create new session
screen -r session_name                     # Restore session
screen -ls                                # List all sessions
screen -d -r session_name                  # Detach and restore session

# tmux usage (recommended)
tmux new -s session_name                   # Create new session
tmux attach -t session_name                # Attach to session
tmux list-sessions                         # List all sessions
tmux kill-session -t session_name          # Kill session

Real-world Scenario: Keep tasks running after SSH connection is lost.

# Use tmux to run long-term tasks
tmux new -s deploy
# Run deployment command in tmux
./deploy.sh
# Ctrl+B, D to detach session
# Reconnect using
tmux attach -t deploy

5. Text Processing and Log Analysis Commands: Your “Data Analyst”

1. tail/head – The “Window” for Log Viewing

# tail usage
tail -f /var/log/app.log                   # Real-time log tracking
tail -n 100 /var/log/app.log               # Show last 100 lines
tail -f -n 0 /var/log/app.log              # Only show newly generated logs

# head usage
head -n 50 /var/log/app.log                # Show first 50 lines
head -c 1K /var/log/app.log                # Show first 1KB content

Real-world Scenario: Real-time monitor application logs.

# Monitor multiple log files simultaneously
tail -f /var/log/nginx/access.log /var/log/nginx/error.log

2. sort/uniq – The “Organizer” for Sorting and Deduplication

# sort usage
sort file.txt                              # Sort
sort -r file.txt                           # Reverse sort
sort -n file.txt                           # Sort numerically
sort -k 2 file.txt                         # Sort by second column

# uniq usage
uniq file.txt                              # Deduplicate
uniq -c file.txt                           # Deduplicate and count
sort file.txt | uniq -c                    # Sort and count unique entries

Real-world Scenario: Analyze access logs to count IP access times.

# Count the most accessed IPs
awk '{print $1}' /var/log/nginx/access.log | sort | uniq -c | sort -nr | head -10

3. cut – The “Scissors” for Field Extraction

# Basic Usage
cut -d: -f1 /etc/passwd                    # Extract first column separated by colon
cut -c 1-10 file.txt                       # Extract characters 1-10
cut -d, -f1,3 file.csv                     # Extract 1st and 3rd columns

# Advanced Usage
cut -d' ' -f1-3 /var/log/access.log        # Extract first three fields

Real-world Scenario: Extract specific information from logs.

# Extract IP and status code from access logs
cut -d' ' -f1,9 /var/log/nginx/access.log

4. wc – The “Counter” for Statistics

wc -l file.txt                             # Count lines
wc -w file.txt                             # Count words
wc -c file.txt                             # Count characters
wc -l /var/log/*.log                       # Count lines in multiple files

Real-world Scenario: Count the size of log files.

# Count lines in all log files
find /var/log -name "*.log" -exec wc -l {} + | tail -1

6. Practical Tips and Combined Commands: Your “Toolbox”

1. Pipes and Redirection: The “Connectors” of Commands

# Pipe usage
ps aux | grep nginx                        # Find nginx process
cat file.txt | grep "error" | wc -l        # Count lines containing error
find /var -name "*.log" | xargs grep "error" # Search in multiple files

# Redirection usage
echo "Hello" > file.txt                    # Overwrite write

echo "World" >> file.txt                   # Append write
command 2>&1 | tee output.log              # Output to screen and file simultaneously

2. History Commands and Aliases: The “Accelerators” of Efficiency

# History commands
history                                    # View command history
!123                                       # Execute command number 123 in history
!!                                         # Execute the last command
!grep                                      # Execute the most recent command starting with grep
# Alias settings
alias ll='ls -la'                          # Set alias
alias grep='grep --color=auto'             # Colorized grep
alias ..='cd ..'                           # Quickly return to the upper directory

3. Practical One-liner Command Combinations

# View system load
uptime && free -h && df -h

# Monitor network connections
watch -n 1 'netstat -tulpn | grep :80'

# Real-time monitor system resources
watch -n 1 'ps aux --sort=-%cpu | head -10'

# Find large files
find / -type f -size +100M -exec ls -lh {} \; 2>/dev/null

# Count lines of code
find . -name "*.go" -exec wc -l {} + | tail -1

# Batch rename files
for file in *.txt; do mv "$file" "${file%.txt}.bak"; done

7. Summary and Advanced Recommendations

Master the Fundamental Principles of These Commands

  1. 1. Everything is a File: The design philosophy of Linux, understanding <span>/proc</span>, <span>/sys</span> and other virtual file systems
  2. 2. Pipes and Redirection: The core of Unix philosophy, small tools combined to solve big problems
  3. 3. Regular Expressions: The cornerstone of text processing, mastering it is immensely powerful
  4. 4. Processes and Signals: Understanding process lifecycle and signal mechanisms

Advanced Learning Path

  1. 1. Shell Scripting: Combine commands into automated scripts
  2. 2. System Tuning: Use tools like <span>perf</span>, <span>strace</span> for performance analysis
  3. 3. Containerized Operations: Master Linux command applications in Docker, Kubernetes
  4. 4. Monitoring and Alerts: Combine tools like Prometheus, Grafana

Recommended Practical Tools

# Modern tools replacements
htop        # Replace top
bat         # Replace cat
exa         # Replace ls
fd          # Replace find
ripgrep     # Replace grep
jq          # JSON processing

Final Thoughts

These commands are just tools; what truly matters is:

  • System Thinking: Understand problems from a holistic perspective
  • Problem Decomposition: Break down complex problems into simple steps
  • Continuous Learning: Technology evolves rapidly, maintain a passion for learning
  • Practical Verification: Combine theory with practice, validate in real environments

Each command mentioned can be expanded into a separate article, such as network commands, system monitoring commands, system tuning commands, etc. Summarize more, think more, and may every server engineer navigate the world of Linux with ease, becoming a true system architect!

This article is based on practical work experience; if there are any omissions or errors, please feel free to point them out. The best way to learn is to continuously practice and summarize in real work.

Leave a Comment