Consider a scenario where you are just starting to copy a very large file from a flash drive on your Linux system using the command line. Considering that this file is heavy, you know the process will take some time, and therefore you start doing other work.
After a while, you came back, only to see that the team was still working. You decide whether to allow copying operations to continue for a while. After a while, when you look again, you observe that nothing has changed, that is, the copying process did not end and the command did not show an error.
Have you ever faced such a situation? If so, what did you do? Quite frankly, there is nothing special that you can do in such cases, especially if you are working on a Linux system – just right, we’ll either wait, or simply cancel the current operation using Ctrl + C and then start it again.
Would it be better if we could see a progress bar (or something similar) in situations like this, the same way we do when we try to copy a file through the GUI? Definitely a progress bar for command line operations will be very helpful. If you’ve been looking for such a solution, look no further, in this article we’ll take a look at two command line utilities, PV and Progress, that will make life easier for you on the command line.
Please note that all commands and instructions that we have already mentioned in this tutorial have been tested on Ubuntu 14.04.
Linux PV Team
According to the official documentation, the PV command controls the data flow through the pipe. The command outputs the following information about the current operation: time elapsed, percentage of completion (with progress bar), current speed, total bandwidth, and ETA.
“To use it, insert it into a pipeline between two processes, with appropriate options,” explains the man page. “Its standard input will be piped to its standard output and progress will be shown on standard error.”
Now, let’s show the use of the PV command with an example. But before that, make sure the utility is present on your system. If not, you can easily download and install it on Debian systems (e.g. Ubuntu) with the following command:
sudo apt-get install pv
Now, let’s move on to an example. The following figure shows the PV command in action, when I copy, the images are stored inside a directory on my flash drive on the desktop of my system:
As you can see, the PV command displays a progress bar as well as other useful information. This is the default behavior of the command. However, if you want to limit the output, you can do so using display switches. For example, the following command will only display a progress bar and nothing else.
pv -p /media/himanshu/1AC2-A8E3/Maldives-2016/* | gzip > ./Desktop/trip-pictures.gz
This is because we used the -p display switch, which tells pv to only turn on the progress bar. For a complete list of display switches, see commands man page…
Then there are some output modifiers. For example, when used with the -W or -wait option, it will tell it to wait until the first byte has been transferred before showing any progress information or any ETA calculations. This is especially useful in cases where we admit requires additional information before starting.
Finally, the PV team also offers some data transfer modifiers. For example, if you want, you can limit the transmission to a certain number of bytes per second. If you look at the screenshot earlier, the data transfer rate is over 18MBps. Now, suppose you want to limit to 5Mbps, for this you need to run the following command:
pv -L 5m /media/himanshu/1AC2-A8E3/Maldives-2016/* | gzip > ./Desktop/trip-pictures.gz
The -L option followed by ‘5m’ does the trick here. See the above command in action in the following screenshot:
“The suffix ‘k’, ‘m’, ‘g’, or ‘t’ can be added to denote kilobytes (* 1024), megabytes, and so on,” explains the man page. More information on data transfer as well as data transfer modifiers is also available using the man page command.
Linux Progress Command
Progress (formerly known as CV) is a command line utility that provides progress for current operations related to core Coreutils commands such as cp, mv, dd, tar, gzip / gunzip, cat, and more. ” It can also show estimated time and throughputand also provides a ‘top-like’ mode like (monitoring), ”says official documentation…
Before installing Progress, you must first ensure that the ‘Ncurses’ library is on your system, as the command depends on this library. If not, Debian / Ubuntu users can download and install the Ncurses package using the following command:
sudo apt-get install libncurses5-dev
Then download the Progress command package from the GitHub repository using the following command:
git clone https://github.com/Xfennec/progress.git
Enter the Progress directory and run the following commands:
make sudo make install
As you can see, the Progress command gives you information about all the current operations, which includes Coreutils commands. Like any other Linux command line tool, Progress also offers several command line options. Below is a list of options that might be useful to you:
- -m (–monitor) : loop while monitored processes are still running
- -M (–monitor-continuously) : monitoring, never stops (analogue of progress)
- -c (–command cmd) : monitoring only this command name (eg Firefox). This option can be used multiple times on the command line.
- -p (–pid id) : monitor only this numeric process id (ex: `pidof Firefox`). This option can be used multiple times on the command line.
- -i (–ignore-file file) : does not report process “file”. If the file does not exist, you must give the complete and clean absolute path. This option can be used multiple times on the command line.
While the Progress tool is limited to Coreutils commands, PV can be used and generally monitor any activity bar command. Plus, PV is easy to download and install. But before you go ahead and conclude that PV is better than Progress, keep in mind that unlike PV, with progress you shouldn’t change the team you want to control. So, which of the two is better generally depends on your requirements.