Intro
As Linux system administrators, we continuously delve into the boundless ocean of Linux commands to manage and control systems with precision. Some commands are pretty standard and widely known. However, a few lesser-known Linux power commands can make life significantly easier for sysadmins. In this article, we’ll uncover these hidden gems of Linux commands and demonstrate why you won’t be able to live without them.
- lsof
Short for “list open files,” the lsof command can be a lifesaver. It displays information about files that are opened by processes. A versatile command, lsof can help troubleshoot network issues and monitor system activities.
Command Example:
lsof -i
This will display all network connections.
- ncdu
“ncdu” or NCurses Disk Usage, presents disk usage statistics in an organized and easy-to-read format. It’s particularly handy when you need to identify large files or directories that are eating up your storage space.
ncdu is not installed by default by many Linux distributions. To install it in a Debian distro, type sudo apt-get install ncdu. To install in a RedHat (RPM) based distro, type sudo dnf install ncdu.
Command Example:
ncdu /
This will show disk usage for the entire file system.
- tmux
Tmux, short for terminal multiplexer, allows you to switch between several programs in one terminal. It’s perfect for managing multiple command line sessions and can detach processes from their controlling terminals, allowing SSH sessions to remain active without being visible.
Command Example:
tmux new-session -s mysession
This will create a new tmux session named “mysession”.
- htop
Although top is widely known and used, htop is an advanced, interactive process viewer. It provides a real-time glimpse into system performance, allowing for real-time interaction with processes.
Command Example:
htop
This will open the htop process viewer.
- strace
Strace is a powerful command that tracks system calls and signals in a process. It’s a wonderful debugging tool when you want to see what a particular process is doing.
Command Example:
strace -p 12345
This will attach to process with PID 12345 and trace its execution.
- mtr
Mtr, short for My Traceroute, combines the functionality of the traceroute and ping programs in a single network diagnostic tool. It continuously updates and displays information about the network connection among the hosts in the traceroute.
Command Example:
mtr google.com
This will trace the route to google.com and display network diagnostics.
- rsync
Rsync, short for remote synchronization, is a fast, versatile file copying tool. It synchronizes files and directories from one location to another while minimizing data transfer using delta encoding when appropriate.
Command Example:
rsync -a /source/directory /destination/directory
This will recursively copy files from the source to the destination directory.
- awk
While it’s known as a programming language, awk is also a command-line tool that is particularly effective for data extraction and reporting. It processes text files based on patterns and actions.
Command Example:
awk '/pattern/ {print $3}' filename
This command prints the third field of every line in filename where “pattern” matches.
9. iftop
The iftop command displays bandwidth usage on an interface by host. Like top, it gives live, real-time data. It’s particularly handy when you want to identify which hosts are consuming bandwidth.
Command Example:
iftop -i eth0
This command shows the network bandwidth usage on the eth0 interface.
- ddrescue
As a data recovery tool, ddrescue can copy data from one file or block device to another, handling errors, making it a great tool for recovering data from failing hard drives.
Command Example:
ddrescue /dev/sda1 /dev/sdb1 logfile
This will attempt to recover the data on /dev/sda1 (source) to /dev/sdb1 (destination), with the progress recorded in logfile.
Conclusion
These ten lesser-known Linux power commands can supercharge your daily sysadmin tasks and transform your troubleshooting and system management efficiency. Try incorporating these commands into your repertoire, and you’ll find them indispensable in your Linux system administration toolkit.