Tools for the command line seem to be a relict of the past. Who wants to deal with various commands having cumbersome options and syntax when you can acheive the same using a specialized tool with an elegant GUI? Or maybe even Excel.
Reasons to master basic command line tools are manyfold
- They are available for most platforms. No need to learn a different set when switching from one operating system to another.
- Each of them is quite specialized but they can be easily combined to perform relatively complex tasks.
- Easy to integrate into scheduled tasks
You’ll read the term Unix various times in this article. It is used as a common term which includes Linux and Mac OS X. The tools mentioned in this article are all published by the Free Software Foundation as part of their GNU project. As they form an important part of any Linux distribution, these systems are often called GNU/Linux systems. A port of the tools for Windows is available from Sourceforge. Just unzip the archive and add the contained directory ‘usr/local/wbin’ to your PATH environment variable.
All of the listed commands provide basic help by calling them with the parameter –help. On Unix systems you can usually get more detailed help by typing man <command>. The headings below also link to the corresponding manual page.
Instead of operating on files, most of these command line tools can also operate on standard input which means they can be used as filters and therefore be easily combined.
The Unix equivalent to the DOS command dir. It can list directory content in various formats and sort orders. Using the -1 switch it can also create a simple list containing just the file or directory names each on a separate line.
An improved version of more. Helps to browse through long files which would otherwise scroll out of reach. Allows to scroll up or down through a file as well as to search for text using the ‘/’ command.
The title is misleading, cut allows you to select only certain parts of input lines for output. E.g. if your input lines look like this:
you can print out a list of the contained ZIP codes using cut -d’,’ -f4.
Does what it says. Assuming you run it on the list of ZIP codes mentioned above, you’d get a list of ZIP codes in alphabetical order.
Filter the input so that consecutive identical lines are omitted. Again, if you take a sorted list of ZIP codes and run it through uniq, you’ll get a list of unique ZIP codes.
Print only the first 5 lines of the input stream: head -n 5.
Print all but the first 5 lines of the input stream: head -n -5.
find is a very mighty command due to its many options. It can search for files in a directory tree filtering by file names, types, modification times, ownership, permissions and more. See the man page for find for more detailed information.
NOTE: Windows users take care not to confuse the GNU version of find with the version that is installed with Windows. The GNU version is much more flexible.
by simply running gzip with a file name as the only parameter it compresses a file and replaces it with its gzipped version.
Can also be used to compress or uncompress standard input and thereby acting as a filter.
Tar is not only useful for backups to tape but a very versatile archiving utility.
Filters the input (stdin or a file) for lines matching a given pattern and prints only those. May also be used to do the opposite or simply list files which have matching content.
What should I say? That’s what it does.