Introduction
As a sysadmin, you often come across complex tasks that require more than just basic commands. That’s why it’s important to learn some intermediate-level Linux commands that can make your work easier and more efficient.
These commands can help you automate repetitive tasks, manage processes, and monitor system performance, among other things. In this article, we will explore some of these commands and their usage.
Pro Tip!
Just like the previous article dropping in a friendly advice that refer to man pages for learning more in detail about each commands using the man <command_name>
Monitoring and Performance
-
sar - The sar command is used to collect, report, and save system activity information.
It is helpful for monitoring system performance and diagnosing issues.
Terminal window sar -u 5 10This command will display CPU utilization statistics every 5 seconds, 10 times.
-
atop - The atop command is used to monitor system resources and processes.
It provides a detailed view of the system activity and helps in identifying performance bottlenecks.
Terminal window atop -r /var/log/atop/atop_20230301This command will display the system activity for a specific date.
-
free - Display the amount of free and used memory in the system.
Terminal window free -hThis will display the data in a human-readable format.
Process Management
-
ps - Display information about the currently running processes.
Terminal window ps -aux -
kill - Send a signal to a process, which can be used to terminate the process.
Terminal window kill -9 1234This will kill the process which has the
PID
of 1234 -
pkill - Kill processes based on their name or other attributes.
Terminal window pkill -f firefoxThis will kill the firefox process.
-
nice - nice command is used to set the priority of a process.
It is often used to give lower priority to CPU-intensive processes so that they don’t hog the system resources.
Terminal window nice -5 wget https://akashrajpurohit.comTo set negative priority you can use a double hyphen
Terminal window nice --5 wget https://akashrajpurohit.com -
renice - Change the priority of an already running process.
Terminal window renice +5 1234This will change the priority of the process with
PID
1234. -
top - Displays real-time information about running processes and system resources.
Terminal window top
Enjoying the content? Support my work! 💝
Your support helps me create more high-quality technical content. Check out my support page to find various ways to contribute, including affiliate links for services I personally use and recommend.
Networking Commands
-
traceroute - Traces the route taken by packets over an IP network.
Terminal window traceroute google.com -
tcpdump - Captures network traffic in real-time and saves it to a file.
Terminal window tcpdump -i eth0 -w capture.pcap -
netstat - Displays information about network connections, routing tables, and network interfaces.
Terminal window netstat -ano | grep ESTABLISHED -
nmap - Scans a network and discovers open ports and services.
Terminal window nmap -sS -O 192.168.1.1/24
Disk Management
-
lsof - The lsof command is used to list open files on the system. It is helpful for identifying processes that are using a specific file or disk partition.
Terminal window lsof /dev/sda1This command will list all processes that are using the /dev/sda1 disk partition.
-
blkid - The blkid command is used to display information about block devices. It is helpful for identifying disk partitions and their properties.
Terminal window blkid /dev/sda1This command will display the properties of the
/dev/sda1
disk partition. -
fdisk - fdisk command is used to list, create, delete, or modify partitions on a hard disk.
Terminal window fdisk -lThis command will list the partition tables for the hard drive.
Miscellaneous Commands
-
sed - A stream editor for filtering and transforming text.
Terminal window sed 's/foo/bar/g' input.txt > output.txt -
awk - A versatile programming language for text processing and data extraction.
Terminal window cat access.log | awk '{ print $1 }' -
tar - A utility for creating and manipulating tar archives.
Terminal window tar -czvf archive.tar.gz file1 file2 dir1 -
find - Searches for files and directories that match certain criteria.
Terminal window find /var/log -type f -name "*.log" -mtime +7 -exec rm {} \;
Conclusion
These are some of the intermediate-level Linux commands that a system admin may use while maintaining a Linux server.
However, this is not an exhaustive list, and there are many more commands that you can explore as you become more experienced with Linux administration.
If you are someone who manages Linux servers a lot and want to add/edit some of the commands then do let me know by reaching out on any social media platform.