Monitoring the execution progress of Linux commands using the PV command

Source: Internet
Author: User

If you are a Linux system administrator, there is no doubt that you have to spend a lot of time working on the command line: Installing and uninstalling software, monitoring system status, copying, moving, deleting files, checking errors, and so on. Most of the time you enter a command and wait a long time until the execution is complete. There are times when you execute a command that hangs, and you can only guess the actual situation of the command execution.

Typically, Linux commands do not provide information about progress, which is especially important, especially if you have only a limited amount of time. This does not mean that you are helpless-there is now a command, PV, which displays the progress information of the command currently executing at the command line. In this article we will discuss it and illustrate its characteristics in a few simple examples.

PV command

Developed by Andrew Wood, PV is the abbreviation for pipe Viewer, which means that information about the progress of data processing is displayed through the pipeline. This information includes the time that has been spent, the percentage of completion (shown through the progress bar), the current speed, the total data transferred, and the estimated time remaining.

"To use PV, you need to match the appropriate options to put it in a pipeline between two processes. The standard input of the command will pass through the standard output, and the progress will be output to the standard error output. ”

The above explanation comes from the help page of the command.

Download and install

Debian's operating system, such as Ubuntu, can be easily installed using the following command of PV:

    1. sudo apt-get install pv

If you use other distributions, you can install PV on your system using your own package management software. Once PV is installed you can use it on various occasions (see below). It is important to note that all of the following examples use the PV 1.2.0.

Features and usage

Most of the usage scenarios for our (users using the command line on Linux) are the commands to copy movie files from a USB drive to your computer. If you use CP to accomplish the above tasks, you will not know what is going on until the entire replication process is complete or error-prone.

However, the PV command is helpful in this scenario. Like what:

    1. pv /media/himanshu/1AC2-A8E3/fNf.mkv > ./Desktop/fnf.mkv

The output is as follows:

So, as you can see, this command shows a lot of useful information about the operation, including the amount of data that has been transferred, the time spent, the transfer rate, the progress bar, the percentage of progress, and the remaining time.

pvThe command provides a variety of display options switches. For example, you can use -p to display percentages, -t to show time, to -r represent the transfer rate, and to -e represent the ETA (LCTT: Estimated time remaining). The good thing is that you don't have to remember an option because the default options are enabled. However, if you only have one of these messages, you can complete the task by controlling these options.

There is also an -n option to allow the PV command to display an integer percentage that displays a number per line on the standard error output to replace the usual visual progress bar. Here is an example:

    1. pv -n /media/himanshu/1AC2-A8E3/fNf.mkv > ./Desktop/fnf.mkv

This particular option is well suited for situations where you want to pass the output to the dialog command.

Next there is a command-line option that -L allows you to modify the transmission rate of the PV command. As an example, use the-l option to limit the transfer rate to 2mb/s.

    1. pv -L 2m /media/himanshu/1AC2-A8E3/fNf.mkv > ./Desktop/fnf.mkv

As you can see, the data transfer speed is limited as per our requirements.

Another scenario where PV can help is to compress files. Here's an example to explain how to work with compression software gzip.

    1. pv /media/himanshu/1AC2-A8E3/fnf.mkv | gzip > ./Desktop/fnf.log.gz

Conclusion

As mentioned above, PV is a very useful gadget that can save you valuable time if the command does not perform as expected. And the displayed information can also be used in shell scripts. I strongly recommend you to use this command, it is worth a try.

Monitoring the execution progress of Linux commands using the PV command

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.