Linux Utilities You Should Know About
by Milinda Lakmal
Utility applications in Linux which are(most of them) originally created for Unix and ported to Linux can be used to make every Linux users life easier. It doesn’t matter whether you are a beginner or a hard core Linux geek, if you know the tools it’ll save you lot of time.
In this post I am going to give you introduction to several utilities available on Linux that originated from Unix based on the recent posts by Peteris Krumins. I am planning to update this post time to time once he add new articles about more tools.
Pipe Viewer
Pipe viewer (Written by Andrew Wood) or pv in short can be used inserted into any normal pipeline between two processes to give a visual indication of how quickly data is passing through, how long it has taken, how near to completion it is, and an estimate of how long it will be until completion.
Default Ubuntu installation doesn’t come with this tool. You need to install it using ‘sudo apt-get install pv’ command.
To get start with pv, lets use this to monitor the progress of compressing large file containing giga bytes of information in to a small file. The normal way to do this using gzip is like following.
But this command won’t tell you how much time it takes to compress this file or monitor the progress of compression.
By using pv you can precisely time how long it will take. Take a look at doing the same through pv:
69MB 0:00:04 [ 15MB/s] [==================> ] 74% ETA 0:00:01
Pipe viewer acts as “cat” here, except it also adds a progress bar. We can see that gzip processed 69MB of data in 4 seconds. It has processed 74% of all data and it will take 1 more seconds to finish.
There are several advance usage patterns of pv command and I am not going to cover those.Please refer the article from Peteris to explore more about pv command.
lsof(list open files)
Peteris called this tools as the Swiss Army Knife of Unix Debugging. lsof is a utility command that you can used to list information about files opened by Unix/Linux processes. In Unix/Linux every things is a file: pipes are files, IP sockets are files, unix sockets are files, directories are files, devices are files, inodes are files… So you know the advantage of this kind of tools where every thing is a file.
Using lsof
Here are some common uage scenarios of lsof comand extracted from catonmat.net blog. You must have root permission to get the information about all the open files using lsof. Unless otherwise you’ll only get information set of files which you have permission to access them.
List all open files
Running lsof without any arguments lists all open files by all processes.
Find who’s using a file
With an argument of a path to a file, lsof lists all the processes, which are using the file in some way.
You may also specify several files, which lists all the processes, which are using all the files:
Find all open files in a directory recursively
With the
argument lsof finds all files in the specified directory and all the subdirectories.
There more use cases of lsof command like getting open files by process, open files by users, list all network connections, list all TCP connections, list network activity by user and etc. Please refer blog post from Peteris for those usage scenarios. You can find some examples of lsof from this link also.