Essential Linux Commands for Backend Developers: Network/Process/Server Resource Management

1. Network Management Commands

1. <span>ping</span>: Network Connectivity Test

# Test basic connectivity (send 4 packets)
ping -c 4 api.example.com

# Continuous testing (test 10 times per second)
ping -i 0.1 -c 10 api.example.com

Application Scenario: Use <span>ping</span> to confirm network connectivity. If ping fails, it indicates a network issue; if it pings successfully but the connection fails, it may be a port issue or application configuration problem.

2. <span>netstat</span>: Port and Connection Monitoring

# View all listening ports
netstat -tuln

# View a specific port (e.g., 8080)
netstat -tuln | grep :8080

# View process and port association (most commonly used!)
netstat -tulnp

Application Scenario: When starting an application and receiving a “port already in use” message, use <span>netstat -tulnp</span> to quickly find the process ID occupying the port, deciding whether to terminate that process or modify the application configuration.

3. <span>curl</span>: HTTP Request Testing

# Send a GET request
curl -v https://api.example.com/v1/data

# Send a POST request (with JSON data)
curl -X POST -H "Content-Type: application/json" -d '{"key":"value"}' https://api.example.com/v1/data

# Save response to a file
curl -o response.json https://api.example.com/v1/data

Application Scenario: Validate whether the API interface works correctly during the development phase or troubleshoot third-party API call issues in the production environment.

4. <span>traceroute</span>: Network Path Analysis

traceroute api.example.com

Application Scenario: When accessing a service is slow, use <span>traceroute</span> to identify bottleneck nodes in the network path, determining whether it is a local network issue or a remote server issue.

5. <span>ss</span>: Modern Network Connection Viewer (replacement for netstat)

# View all TCP connections
ss -tuln

# View a specific port
ss -tuln | grep :8080

Application Scenario: <span>ss</span> is faster than <span>netstat</span> and provides more detailed TCP connection status information.

2. Process Management Commands

1. <span>ps</span>: Process Status Snapshot

# View all processes (including those of other users)
ps aux

# View a specific process
ps aux | grep java

# Display process relationships in a tree structure
ps axf

Application Scenario: Confirm whether a service is running or view the parent-child relationships between processes.

2. <span>top</span>: Real-time System Monitoring

top
# In the top interface:
# P - Sort by CPU
# M - Sort by memory
# k - Terminate process (input PID)
# q - Exit

Application Scenario: When the server suddenly slows down, start <span>top</span> to check CPU and memory usage, quickly locating high-load processes.

3. <span>kill</span>: Process Termination

# Terminate a specific process (by PID)
kill 12345

# Force termination (if normal kill is ineffective)
kill -9 12345

# Terminate by process name (exact match)
pkill -f "java -jar myapp.jar"

Application Scenario: Quickly terminate a running test service to avoid port conflicts.

4. <span>nohup</span> and <span>&</span>: Run Commands in the Background

# Run in the background and ignore hangup signals
nohup java -jar myapp.jar &amp;

# View background processes
jobs

# Bring a background process to the foreground
fg %1

Application Scenario: When running long tasks, use <span>nohup</span> and <span>&</span> to allow tasks to run in the background, ensuring they won’t be interrupted even if the SSH connection is closed.

5. <span>jps</span>: Java Process Management

# View all Java processes
jps

Application Scenario: Confirm whether Java processes are running normally.

3. Server Resource Management Commands

1. <span>df</span>: Disk Space Usage

# View disk space usage (human-readable)
df -h

Application Scenario: When the server runs out of disk space, use <span>df -h</span> to quickly confirm disk usage.

2. <span>du</span>: Directory Size View

# View directory size (human-readable)
du -sh /var/log

# Find large files (>100MB)
find / -type f -size +100M -exec ls -lh {} \;

Application Scenario: When disk space is low, use <span>du -sh</span> to locate large directories, then use <span>find</span> to find specific large files.

3. <span>free</span>: Memory Usage

# View memory usage (human-readable)
free -h

# View detailed memory usage
free -m

Application Scenario: When there is a memory leak in a Java application, use <span>free -h</span> to confirm memory usage and determine if JVM parameters need adjustment.

4. <span>vmstat</span>: Comprehensive System Performance Monitoring

# View system performance statistics (refresh every second)
vmstat 1

Application Scenario: When overall system performance declines, <span>vmstat</span> provides comprehensive information on CPU, memory, I/O, etc., helping to determine whether the bottleneck is in CPU, memory, or I/O.

5. <span>iostat</span>: I/O Performance Monitoring

# View disk I/O statistics
iostat -x 1 3

Application Scenario: When application read/write to disk is slow, use <span>iostat</span> to check disk I/O utilization and determine if there is a disk performance bottleneck.

6. <span>lsof</span>: View Files Opened by Processes

# View processes occupying a port
lsof -i :8080

# View which processes have opened a specific file
lsof /var/log/app.log

Application Scenario: When needing to delete a file currently in use by a process, first use <span>lsof</span> to confirm which processes are using it.

7. <span>systemctl</span>: Service Management

# View service status
systemctl status nginx
# Restart
systemctl restart nginx
# Start
systemctl start nginx

Application Scenario: Use <span>systemctl</span> for standardized operations when managing services like Nginx and MySQL on Linux servers.

Awesome! Seven Excellent Methods to Optimize if-else Statements in SpringBoot

Using EasyExcel in SpringBoot to Export Multiple Excel Files in Parallel and Compress for Zip Download
From the Principles of MySQL Row Format: Why NULL is Not Recommended in Development Standards? How is Data Stored on Disk?
Single Token Authorization and Renewal Scheme Based on JWT in SpringBoot
Token Login Authorization, Renewal, and Active Termination Scheme in SpringBoot (Redis + Token)
Summary of Four Token Authentication Design Methods in Microservices

Compilation of 40 Core MySQL Interview Questions

Summary of Distributed Transaction Solutions: Local Message Asynchronous Confirmation, Reliable Message Final Consistency, Maximum Effort Notification

Summary of MySQL and Redis Cache Consistency Issues and Solutions

Technical Communication Group:https://www.yuque.com/diguabobo/fqyfiq/sgpbh2rsw3k0hlzd

Leave a Comment