Here are five powerful Linux commands for system diagnostics and administration, along with practical examples:
- Filter Active Network Connections on a Specific Port
netstat -tulnp | grep ':22' | awk '{print $5, $7}'
Explanation: `netstat` lists active TCP/UDP connections, `grep` filters connections on port 22 (SSH), and `awk` extracts the remote IP and corresponding process.
2. **List Users with Active SSH Connections**
who | awk '{print $1}' | sort | uniq -c | sort -nr
Explanation: `who` lists logged-in users, `awk` extracts usernames, and `sort` organizes the results by the number of connections.
3. **Find Recently Modified Files by a User**
find /home -type f -user utilisateur -mtime -7 -ls | awk '{print $7, $11}'
Explanation: `find` locates files modified by “utilisateur” in the last 7 days, and `awk` displays file size and path.
4. **Monitor Failed SSH Login Attempts**
grep 'Failed password' /var/log/auth.log | awk '{print $(NF-3)}' | sort | uniq -c | sort -nr | head -10
Explanation: `grep` searches for failed login attempts in auth.log
, and `awk` extracts the source IPs, sorted by frequency.
5. **Check Memory Usage by Process (Sorted)**
ps aux | awk '{print $2, $4, $11}' | sort -k2nr | head -10
Explanation: `ps aux` lists all processes with memory usage, `awk` extracts PID, memory usage (%), and command, and `sort` ranks the top 10 memory-intensive processes.
**What Undercode Says**
Linux system administration is a critical skill for IT professionals, and mastering command-line tools can significantly enhance productivity and security. The commands shared above are essential for diagnosing network issues, monitoring user activity, and managing system resources. For instance, `netstat` and `grep` are invaluable for network troubleshooting, while `find` and `awk` streamline file management and log analysis. Additionally, monitoring failed SSH attempts with `grep` and `awk` helps identify potential security threats.
To further expand your Linux expertise, consider exploring advanced commands like `lsof` for open files, `iptables` for firewall management, and `cron` for task automation. For Windows users, PowerShell commands like `Get-Process` and `Test-NetConnection` offer similar functionality. Always ensure logs are regularly reviewed and system permissions are properly configured to minimize vulnerabilities.
For more in-depth tutorials, visit:
By integrating these commands into your daily workflow, you can efficiently manage systems, enhance security, and troubleshoot issues with confidence.
References:
Hackers Feeds, Undercode AI