The ten Linux commands listed in this article are not well known but can be pretty useful for systems administrators.
Linux is so vast that even after working with it for a few years, we keep discovering new commands that enable us to do our tasks more efficiently and productively. I have compiled a few commands and utilities that will be useful to administrators and even typical users.
1. The watch command
The watch command can be used to repeat a command at fixed intervals. The default interval is 2 seconds or the users can set their own interval with the -n option. To run the free command every 5 seconds, use the following command:
$watch -d -n 5 free
The -d option highlights the change, which is a really useful option. Type Ctrl-C to quit and come back to the prompt.
2. An audible ping
The ping command is often used to check whether a server or a link is up. We may have to wait for some time, and if you dont want to watch the screen continuously when you are busy doing something else, the solution is to make the ping audible by using the -a option.
$ping -a 192.168.10.1
3. Overwriting a file
The operating system does not completely erase a file when the file is deleted. The file could be recovered by third party forensic tools. But we can use the shred command to overwrite a file, to make it almost impossible for it to be recovered. The file is overwritten three times, by default, which can be changed by the -n option.
$shred -n 5 trial.txt
The above command will overwrite the file trial.txt five times. The -u option can be used to remove a file after overwriting.
$shred -u trial.txt
The shred tool may not work in journaling file systems and RAID file systems.
Even the srm (secure remove) and wipe utilities can be used to securely remove a file, though they are not installed by default in most Linux systems.
4. The file command
The file command is used to know what type the file is. The command is shown below:
$file filename
This is particularly useful for admins in a multi-user system where the users may want to hide their MP3 or other audio/video files. It can even be used to test the file types in a Windows share by mounting the Windows share in Linux using Samba.
5. The mtr utility
The mtr utility (short for my traceroute) can be used as a network diagnostic tool, and combines the functionality of traceroute and ping utilities in one single program to provide a lot more statistical information. The tool checks the connection between the source (on which the command has been given) and the destination. A table of values is given as output and is refreshed continuously till the user presses Ctrl-C. The -r option gives a static report. Ideally, both ends of the network have to be tested using mtr to get a complete picture.
$mtr 192.168.11.1
6. The htop tool
As per the man page, htop is an ncurses-based process viewer in Linux. It is an improvement over top. In fact, you may stop using top after getting used to htop. It allows you to scroll vertically and horizontally, so that you can see all the processes running on the system along with the commands that initiated the processes. Tasks can be filtered based on user accounts and a process can be killed within htop. This tool displays the output in colour, but the display format of the process details remains the same as in the output of the top command.
7. The logsave utility
The logsave utility captures the output of any command and stores it in a file along with the starting and ending time of the command. The unique aspect of this utility is that if the directory into which you are writing the output file does not exist, it is queued in memory and written after the directory is created. This is particularly useful for saving command outputs while booting up.
$logsave filelist.txt ls -l
The output of the logsave command is given below in Figure 5.
8. The look command
The look command displays all the lines in a file that start with a particular string. The input file should be sorted as look performs a binary search. If a file name is not mentioned, then by default, the /usr/share/disct/words file is used. Only alphanumeric characters are compared and the f option ignores the case of the letters of the alphabet.
$look printf avltree.c
The grep command can be used to do the same task, but the performance of look is better. Its other use is that it can check the spelling of a word. Type the first few letters of any word that you want the spelling of and the command will display all the words starting with those letters.
9. The stat utility
The stat command displays the status of a file or a file system. The information is much more detailed compared to that given by ls -l and includes the absolute path name of the file, the number of blocks used by the file, the I/O block size, inode, the access specifier, access time, time of modification, etc. It can also be used to obtain information about the file system.
10. The Midnight commander
The Midnight commander (mc) is a powerful text based file manager. It is a directory-browsing tool and allows all the basic file operations. It can be used to view the contents of archived files, browse the ftp repository of a remote server and undelete files in the older file systems, and has a built-in text and hex viewer. It even allows you to use the command line within it. It can be started by typing mc at the prompt.
$mc