Linux has a huge collection of command-line tools ranging from tools you use everyday like ls, cd and ps to more obscure tools that you might not have used or even heard of.
We're going to look at five of these more obscure tools that could make your life easier. We'll briefly look at each command and its flags and options but don't forget to check each command's man page for all the possible flags and options.
logsave
The first tool we're going to look at is . The logsave command saves the output of a command to a log file:
Here, the logsave command saves the output of the df command to the file /var/log/partsize file – it will also add a timestamp and output the results of the command to standard out.
Doesn't sound overly interesting, does it? Well the special magic of is that if the file, in our case /var/log/partsize, does not exist then will queue the data in memory and wait for the file to appear. This is perfect for tracking the output of comm...
To continue reading for free, register below or login
To read more you must become a member of SearchEnterpriseLinux.com
');
// -->

ands run doing the boot process when the partition you are writing to is not yet mounted. I use quite a bit during automatic provisioning and bootstrapping to save command output that might otherwise be lost.
diff3
The next tool is the diff3 command. You may have used the diff command to generate differences between files. performs the same function for three files instead of two, but lacks some of diff's more sophisticated options. So let's take a simple example. We have three files: cat, dog, and mouse. They each contain a string. We can compare them all with like so:
The diff3 command displays the different string from each of the three files. You can also specify as one of the files. This will feed in standard input to compare against the other files.
You can also use the flag to incorporate changes in all the files and highlight any conflicts:
pstree
You've probably already used to list processes on your hosts. But you may not have heard of -- a command that displays your processes in a tree. Each process either branches out from the init process, from a PID you can specify, or from a user you can specify. Each process and its sub-processes are displayed as you can see below:
[IMAGE]
The command also has some command flags you can use, for example the –a flag will display the command line used for the process and –p will add the process ID of the process to the tree.
nl
The nl command is very little known but performs a nifty little function – it adds line numbers to output sent to the command. Let's take a simple example and run the nl command against a file called dog.
has taken the contents of the dog file and outputted it prefixed with line numbers. You can then pipe this output to a new file.
We can then display the contents of the file with our new numbered lines:
split
The last command we're going to look at is . The split command splits files into pieces usually based on size. I use it to split large log files into more manageable pieces, for example:
The split command has options for dividing files by bytes and numbers of lines, here we've divided the largelogfile into one million byte chunks by specifying the option (you can specify b for bytes, k for kilobytes, g for gigabytes, etc).
We could divide the file by numbers of lines like so:
Here the file would be divided into 1,000 line chunks.
In our examples each chunk will be stored in /tmp and the filename will be prefixed with the name smallerfile. The first file would be smallerfileaa, and the second smallerfileab, etc. You can also use the flag to number the chunks numerically instead of using alphabetic increments. Lastly, instead of specifying a file you can use to indicate that should take input from standard input and divide that into separate files.
ABOUT THE AUTHOR: James Turnbull works for the National Australia Bank as the manager of the CERT (Computer Emergency Response Team). He is an experienced infrastructure architect with a background in Linux/Unix, AS/400, Windows, and storage systems. He has been involved in security consulting, infrastructure security design, SLA and service definition and has an abiding interest in security metrics and measurement. James is also involved in the Free and Open Source Software community as a developer and contributor.