How to monitor the execution progress of Linux commands using pv commands

Source: Internet
Author: User

How to monitor the execution progress of Linux commands using pv commands

If you are a Linux system administrator, you must spend a lot of time on the command line to install and uninstall software, monitor the system status, copy, move, and delete files, and so on. In most cases, you enter a command and wait a long time until the execution is complete. Sometimes the command you run is suspended, and you can only guess the actual situation of the command execution.

Generally, Linux commands do not provide progress-related information, which is especially important, especially when you only have a limited time. However, this does not mean that you are helpless-now there is a command, pv, which will display the progress of the current Command executed on the command line. In this article, we will discuss it and illustrate its features with a few simple examples.

 

PV command

PV, developed by Andrew Wood, is short for Pipe Viewer. It means displaying data processing progress information through pipelines. This information includes the time consumed, the percentage of completion (displayed through the progress bar), the current speed, all transmitted data, and estimated remaining time.

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

The preceding explanation is from the help page of the command.

 

Download and install

For Debian operating systems, such as Ubuntu, you can use the following command to install PV:

  1. sudoapt-get install pv

If you are using another release version, you can use your own package management software to install PV on your system. Once PV is installed, you can use it on various occasions (see below ). Note that pv 1.2.0 is used in all the examples below.

 

Features and usage

Most of the commands we use in linux are to copy movie files from a USB drive to your computer. If you use cp to complete the preceding task, you will not be clear about the situation until the entire replication process ends or an error occurs.

However, pv commands are helpful in this scenario. For example:

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

The output is as follows:

Pv-copy

As you can see, this command displays a lot of useful information related to operations, including the amount of data that has been transferred, the time spent, the transmission rate, the progress bar, and the percentage of progress, and the remaining time.

pvThe command provides multiple display options. For example, you can use-pTo display the percentage,-tTo display the time,-rIndicates the transmission rate,-eStands for eta (LCTT: estimated remaining time ). The good thing is that you don't have to remember an option, because these options are enabled by default. However, if you only need one of them, you can control these options to complete the task.

Here is another-nOption to allow the pv command to display the integer percentage. A number is displayed on each line of the standard error output to replace the normal visual progress bar. The following is an example:

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

Pv-numeric

This special option is very suitable for certain situations. For example, you want to use pipelines to send the output to the dialog command.

Next, there is a command line option,-LYou can modify the transmission rate of the pv command. For example, the-L option is used to limit the transmission rate to 2 MB/s.

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

Pv-ratelimit

As you can see, the data transmission speed is limited according to our requirements.

Another scenario where pv can help is to compress files. Here is an example to explain how to work with the compression software Gzip.

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

Pv-gzip

 

Conclusion

As mentioned above, pv is a very useful tool that can help you save valuable time without executing commands as expected. The displayed information can also be used in shell scripts. I strongly recommend that you use this command. It is worth a try.

Via: https://www.maketecheasier.com/monitor-progress-linux-command-line-operation/

Author: Himanshu Arora Translator: ezio Proofreader: wxy

This article was originally compiled by LCTT and launched with the honor of Linux in China

This article permanently updates the link address:

Related Article

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.