Raspberry Pi

How to Monitor Progress of Data on Raspberry Pi using ā€˜pvā€™ Command

The pv (pipe viewer) is a command line utility used to monitor the progress of piped commands. The pv displays the complete progress bar, data transfer speed, estimated and remaining time, time elapsed and the transferred data in bits/bytes per seconds. While working with Linux-based systems such as Raspberry Pi, pv is of utmost importance because many times when commands are piped together, the process goes on in the background and the user does not know how long it is going to take and when will the process finish.

In this writeup, we will discuss the way to monitor the progress of data using the pv command.

How to Monitor the Progress of Data on Raspberry Pi using ā€˜pvā€™ Command?

In the Raspberry Pi system, the pv is not pre-installed but it can be downloaded easily using the apt package management tool.

Install pv on Raspberry Pi

Follow the below-given steps to install pv on Raspberry Pi:

Firstly, update/upgrade the repository using the below-written command:

$ sudo apt update

$ sudo apt upgrade

Then install pv from the Raspberry Pi repository using the below-written command:

$ sudo apt install pv

Verify the installation of pv by running the below-written command:

$ pv --version

pv Command Syntax

There are different syntaxes, which can be followed to use the pv utility, such as:

Syntax 1

This syntax is used when the content of one file is required to be copied into another location or file:

$ pv filename > outputfile

Syntax 2

This syntax is used when two commands are piped together, in which the output of first command act as an input to the next command:

$ command1 | pv | command2

How to Use pv Utility to Monitor Progress

Now letā€™s see how you can use the pv command to monitor the progress of different processes like the copying process, creating a backup or compressing the data.

1: Monitor Progress While Copying the Data

To get to know about the progress while copying content from one file to another, you can follow the syntax 1, which is already mentioned in the article:

Example

$ pv script.py> $HOME/Documents/script.py

Script.py is my file which I have copied in documents using the above written command:

You will see the progress of the file on the terminal. The same command can be followed for other files too.

2: Monitor Progress While Compressing the Data

To monitor the progress of a data compression process, the users can use the following pipeline command with pv, and as an output the percentage of deflation will also display on the terminal:

$ pv <original file>| zip> [output zipped file]

3: Monitor Progress While Backing Up the Data

To monitor the progress while creating a backup for a directory, just run the below-written command:

$ tar -czf - ./<Directory name> | (pv -p --timer --rate --bytes > backup.tgz)

The above command displays the progress of data backup by setting up the timer and shows you the data transfer rate during the file backup.

To find out detail about different pv options, open the manual on the terminal using the following command:

$ man pv

Read out the manual to get used to the pv command if you are new to it.

Conclusion

To monitor the progress of data, the pv (pipe viewer) utility is used, which can be installed by using the apt command. The pipe viewer command has different syntaxes which are discussed in the article. Also, there are different options/modifiers which can be used with the pv command to perform the desired operation for the progress bar.

About the author

Zahra Zamir

An Electronics graduate who loves to learn and share the knowledge, my passion for my field has helped me grasp complex electronics concepts and now I am here to share them with others.