Monday, August 10, 2020

Monitor the progress of copy operation with pv

 Sometimes, when we need to copy a big file, let's say from our linux box, to a flash drive, and we just used the "cp" command. After a while, we are anxious to know what is the progress, and unfortunately we have forgotten to turn on verbose for the command. 


What to do? Cancellation is not an option, since we would be wasting time restarting the command again if we want to put the verbose option.


Worry not, there is a solution. And this solution is pv. Most of the time it is not installed by default, so we have to install it first.


What is pv? According to its man page, pv will monitor the progress of data through a pipe. Nice!


How do we install it?

$ sudo apt install pv -y


How do we use it? We can track the progress of any command, just by providing the PID of that running command. Let's say we are copying an iso. 

Firstly, get the PID of the cp command., and then run pv against it. 

$ ps -ef | grep iso | grep -v grep | awk '{print $2}'

12345

$ pv -d 12345

and pv will provide you with a nice progress bar, with E.T.A. like below

No comments:

Post a Comment