
Last week, our automation pipeline suddenly failed, and the error message was simply:
Connection refused
The developer said: “The service is down, go check the server.”
I logged into the test machine and resolved it with three commands:
ps -ef | grep order-service # Check processesnetstat -tunlp | grep 8080 # Check porttail -f /var/log/order.log # View logs
In 5 minutes, I identified: the service crashed and did not restart.
This incident made me realize: automation testing is no longer just about writing scripts; it also requires understanding the environment, troubleshooting, and collaboration.
Today, I have compiled a practical list of the 20 most commonly used Linux commands for automation test engineers, categorized by scenario, to help you navigate CI/CD, log analysis, and service validation with ease.

π 1. File and Directory Operations (Daily High Frequency)
1. ls ββ List directory contents
ls -l # Detailed list (permissions, size, time)ls -lh # Human-readable file size (e.g., 2.3K)ls -lt # Sort by modification time (latest first)β
Scenario: Check if the automation script is successfully deployed
2. cd / pwd ββ Change and view directories
cd ~/projects/api-test # Enter project directorypwd # Print current path (confirm location)
3. cat / less / head / tail ββ View files
cat config.yaml # View complete configurationless large_log.log # View large files page by page (press q to exit)head -n 20 report.html # View the first 20 lines of the reporttail -f app.log # **Real-time log tracking (debugging tool!)**π‘ tail -f is the golden command for troubleshooting automation failures!
4. grep ββ Text search (must-know!)
grep "ERROR" app.log # Search for errorsgrep -i "timeout" app.log # Ignore casegrep -n "401" app.log # Show line numbersgrep -A 3 -B 2 "Exception" app.log # Show matching lines with context (before and after)β
Scenario: Quickly locate the cause of automation failure (e.g., token expiration, connection timeout)

π₯οΈ 2. Process and Port Management (Core of Service Validation)
5. ps ββ View processes
ps -ef | grep pytest # Check if the automation process is runningps aux | grep nginx # Check web service
6. netstat / ss ββ View network connections and ports
netstat -tunlp | grep 8080 # Check if port 8080 is occupiedss -tuln # Faster alternative (recommended)β οΈ If command not found, install: yum install net-tools or apt install net-tools
7. kill / pkill ββ Terminate processes
kill -9 12345 # Force kill process with PID 12345pkill -f "pytest" # Kill all processes containing "pytest"β
Scenario: Clean up residual automation processes to avoid port conflicts

π¦ 3. File Transfer and Compression (Essential for Deployment)
8. scp ββ Securely copy files (local β server)
# Upload local script to serverscp test_order.py [email protected]:/home/qa/# Download server logs to localscp [email protected]:/var/log/app.log ./
9. tar ββ Pack and unpack
tar -czvf report.tar.gz reports/ # Compress directorytar -xzvf report.tar.gz # Unpackβ
Scenario: Package automation reports to send to colleagues or archive

π§ͺ 4. Network and Service Testing (Extended Interface Validation)
10. curl ββ Send HTTP requests (no need for Postman)
# GET requestcurl http://api.test.com/users/1# POST JSONcurl -X POST http://api.test.com/login \ -H "Content-Type: application/json" \ -d '{"user":"test","pwd":"123"}'# With Cookiecurl -b "sessionid=abc123" http://api.test.com/profileπ‘ Directly verify interfaces on the server, bypassing local network restrictions!
11. ping / telnet / nc ββ Network connectivity testing
ping api.test.com # Test domain resolution and basic connectivitytelnet db.test.com 3306 # Test if database port is reachablenc -zv redis.test.com 6379 # More modern port probing (netcat)

π 5. System Status and Resource Monitoring (Initial Performance Screening)
12. top / htop ββ Real-time view of CPU/memory
top # Built-in commandhtop # More user-friendly (requires installation: yum install htop)β
Scenario: Is the server lagging during automation execution? Check resource usage!
13. df / du ββ Disk space
df -h # View disk usage (human-readable units)du -sh ./logs # View size of logs directoryβ οΈ Accumulation of automation logs may lead to full disk, causing service downtime!

π οΈ 6. Permissions and Users (Collaboration Pitfalls)
14. chmod ββ Change file permissions
chmod +x run_tests.sh # Add execute permission to scriptchmod 644 config.yaml # Set as read-only configuration
15. chown ββ Change file owner
sudo chown qa:qa report.html # Assign report ownership to qa user

π 7. Scheduled and Background Tasks (CI/CD Extension)
16. crontab ββ Scheduled tasks
crontab -e # Edit scheduled tasks# Run regression every day at 2 AM0 2 * * * cd /project && python -m pytest --html=report.html
17. nohup ββ Run in the background (prevent disconnection)
nohup python long_run_test.py > test.log 2>&1 >β
Scenario: Automation continues to execute after SSH disconnection

π§° 8. Other Useful Commands
18. which / whereis ββ Find command location
which python # View python path (avoid version confusion)
19. history ββ View command history
history | grep curl # Find previously used curl commands
20. alias ββ Set shortcut commands
# Add to ~/.bashrc alias ll='ls -lh'alias logt='tail -f /var/log/test.log'β
Improve daily efficiency!

π‘ Advice for Automation Test Engineers
Do not just memorize commands; understanding the scenarios is more important.
Make good use of pipes | and redirection >: the power of combining commands is immense (e.g., grep ERROR log | wc -l).
Practice in the testing environment, do not be afraid to make mistakes (be cautious in production environments!).
Organize commonly used commands into a cheat sheet, post it at your workstation or save it as notes.

π¬ In Conclusion
Linux is not just the domain of operations and maintenance; it is the second workstation for every automation test engineer.
When you can smoothly check logs, validate services, debug interfaces, and monitor resources on the server,
you are no longer just “the script writer” but a quality guardian who can close the loop on issues.
Mastering these commands is not about becoming an operations engineer, but about doing testing more professionally.

Every interaction is encouragement, and every support promotes growth.
Business cooperation:huaan——9527