Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to use pv command to monitor the progress of Linux command execution

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

Editor to share with you how to use pv commands to monitor the progress of the implementation of Linux commands, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

PV command

PV, developed by Andrew Wood, is short for Pipe Viewer, which means to display information about the progress of data processing through a pipeline. This information includes the time elapsed, the percentage completed (shown by the progress bar), the current speed, all data transferred, and the estimated remaining time.

"to use PV, you need to place it in a pipe between two processes with the appropriate option. The standard input of the command will be passed 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 operating systems, such as Ubuntu, can simply install PV using the following command:

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 in a variety of situations (see below for details). It is important to note that all of the following examples use pv 1.2.0.

Characteristics and usage

The command we (command-line users on linux) use in most usage scenarios is to copy movie files from a USB drive to your computer. If you use cp to accomplish the above tasks, you will not know anything until the whole replication process is over or something goes wrong.

However, the pv command is very helpful in this situation. For example:

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

The output is as follows:

Pv-copy

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.

The pv command provides a variety of display option switches. For example, you can use-p to show the percentage,-t to show the time,-r for the transmission rate, and-e for eta. The good thing is that you don't have to remember one of the options, because they are enabled by default. However, if you only need one of these information, you can accomplish the task by controlling these options.

There is also a-n option to allow the pv command to display integer percentages and one number per line on the standard error output instead of the usual visual progress bar. Here is an example:

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

Pv-numeric

This special option is very suitable for certain situations, such as if you want to pipe the output to the dialog command.

Next, there is a command line option,-L, which allows you to modify the transfer rate of the pv command. For example, use the-L option to limit the transfer rate to 2MB/s.

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

Pv-ratelimit

As can be seen in the picture above, the data transmission speed is limited according to our requirements.

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

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

The above is all the contents of the article "how to use pv commands to monitor the progress of Linux commands". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report