Logo
  • Ubuntu
  • CentOS
  • Debian
  • Fedora
  • RedHat

How to Monitor Progress of (Copy/Backup/Compress) Data using ‘pv’ Command - DesignLinux

Dec 20 2022
designlinux 0 Comments

When making backups, and copying/moving large files on your Linux system, you may want to monitor the progress of an ongoing operation. Many terminal tools do not have the functionality to allow you to view progress information when a command is running in a pipe.

You might also like:

  • Advanced Copy Command – Shows Progress While Copying Large Files in Linux
  • Progress – Show Progress for (cp, mv, dd, tar) Commands in Linux
Show Copy/Backup/Tar File Progress Bar in Linux
Show Copy/Backup/Tar File Progress Bar in Linux

In this article, we shall look at an important Linux/Unix command called pv – Pipe Viewer.

Pv is a terminal-based tool that allows you to monitor the progress of data that is being sent through a pipe. When using the pv command, it gives you a visual display of the following information:

  • The time that has elapsed.
  • The percentage completed includes a progress bar.
  • Shows current throughput rate.
  • The total data transferred.
  • and the ETA (estimated Time).

Table of Contents

  • How to Install pv Command in Linux?
    • Install pv on RHEL-based Linux
    • Install pv on Debian-based Linux
    • Install pv on Other Linux Distributions
  • How Do I Use pv Command in Linux?
    • Pv Display Modifiers Options
    • Pv Display Modifiers Options
  • Pv Command with Examples in Linux
  • Summary

How to Install pv Command in Linux?

The pv command is not installed by default on most Linux distributions, therefore you can install it by following the steps below.

Install pv on RHEL-based Linux

First, you need to turn on the EPEL repository and then run the following yum or dnf command to install it.

# yum install pv
OR
# dnf install pv          

Install pv on Debian-based Linux

$ sudo apt-get install pv

Install pv on Other Linux Distributions

$ sudo emerge -a pv        [On Gentoo Linux]
$ sudo apk add pv          [On Alpine Linux]
$ sudo pacman -S pv        [On Arch Linux]
$ sudo zypper install pv   [On OpenSUSE]    

How Do I Use pv Command in Linux?

pv is mostly used with other programs which lack the ability to monitor the progress of an ongoing operation. You can use it, by placing it in a pipeline between two processes, with the appropriate options available.

The standard input of pv will be passed through to its standard output and progress (output) will be printed on standard error. It has a similar behavior to the cat command in Linux.

The syntax of the pv command is as follows:

$ pv file
$ pv options file
$ pv file > filename.out
$ pv options | command > filename.out
$ comand1 | pv | command2 

The options used with pv are divided into three categories, display switches, output modifiers and general options.

Pv Display Modifiers Options

Some options are under display modifiers.

  • To turn on the display bar, use the -p option.
  • To view the elapsed time, use the --timer option.
  • To turn on the ETA timer which tries to guess how long it will take before the completion of an operation, use the --eta option. The guess is based on previous transfer rates and the total data size.
  • To turn on a rate counter use the --rate option.
  • To display the total amount of data transferred so far, use the --bytes option.
  • To display progress information of integer percentage instead of visual indication, use the -n option. This can be good when using pv with the dialog command to show progress in a dialog box.

Pv Display Modifiers Options

Some options are under output modifiers.

  • To wait until the first byte is transferred before displaying progress information, use the --wait option.
  • To assume the total amount of data to be transferred is SIZE bytes when computing percentage and ETA, use --size SIZE option.
  • To specify seconds between updates, use the --interval SECONDS option.
  • Use --force option to force an operation. This option forces pv to display visuals when standard error is not a terminal.
  • The general options are --help to display usage information and –version to display version information.

Pv Command with Examples in Linux

1. When no option is included, pv commands run with the default -p, -t, -e, -r and -b options.

For example, to copy the opensuse.vdi file to /tmp/opensuse.vdi, run this command and watch the progress bar in the screencast.

# pv opensuse.vdi > /tmp/opensuse.vdi

Copy Files Show Progress Bar

2. To make a zip file from your /var/log/syslog file, run the following command.

# pv /var/log/syslog | zip > syslog.zip

Zip File Show Progress Bar

3. To count the number of lines, words, and bytes in the /etc/hosts file while showing the progress bar only, run this command below.

# pv -p /etc/hosts | wc

Count Lines, Words and Bytes in Linux

4. Monitor the progress of creating a backup file using the tar utility.

# tar -czf - ./Downloads/ | (pv -p --timer --rate --bytes > backup.tgz)

Create Tar Backup: Show Progress Bar

5. In the example, we use the dd command to write the ISO file to the USB flash drive:

# dd if=debian-10.11.0-amd64-DVD-1.iso | pv | dd of=/dev/sda bs=4M

6. Using pv and dialog terminal-based tool together to create a dialog progress bar as follows.

# tar -czf - ./Documents/ | (pv -n > backup.tgz) 2>&1 | dialog --gauge "Progress" 10 70
Create Dialog Progress Box
Create Dialog Progress Box

Summary

This is a good terminal-based tool that you can use with tools that do not have the ability, to monitor the progress of operations such as coping/moving/backing up files, for more options check man pv.

I hope you find this article helpful and you can post a comment if you have any ideas to add about using the pv command. And if you get any errors while using it, you can as well leave a comment.

Related Linux Commands:

  • 21 Tar Command Examples in Linux
  • Most Commonly Used Linux Commands You Should Know
  • 10 Most Dangerous Commands – You Should Never Execute on Linux

Related

Tags: Linux Tricks

How to Install GIMP on Ubuntu 22.04

Prev Post

Progress – Show Percentage of Copied Data for (cp, mv, dd, tar) Commands

Next Post
Archives
  • January 2023
  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • July 2022
  • June 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021
  • February 2021
  • January 2021
  • December 2020
  • November 2020
  • October 2020
  • September 2020
  • August 2020
  • July 2020
  • June 2020
  • May 2020
Categories
  • AlmaLinux
  • Android
  • Ansible
  • Apache
  • Arch Linux
  • AWS
  • Backups
  • Bash Shell
  • Bodhi Linux
  • CentOS
  • CentOS Stream
  • Chef
  • Cloud Software
  • CMS
  • Commandline Tools
  • Control Panels
  • CouchDB
  • Data Recovery Tools
  • Databases
  • Debian
  • Deepin Linux
  • Desktops
  • Development Tools
  • Docker
  • Download Managers
  • Drupal
  • Editors
  • Elementary OS
  • Encryption Tools
  • Fedora
  • Firewalls
  • FreeBSD
  • FTP
  • GIMP
  • Git
  • Hadoop
  • HAProxy
  • Java
  • Jenkins
  • Joomla
  • Kali Linux
  • KDE
  • Kubernetes
  • KVM
  • Laravel
  • Let's Encrypt
  • LFCA
  • Linux Certifications
  • Linux Commands
  • Linux Desktop
  • Linux Distros
  • Linux IDE
  • Linux Mint
  • Linux Talks
  • Lubuntu
  • LXC
  • Mail Server
  • Manjaro
  • MariaDB
  • MongoDB
  • Monitoring Tools
  • MySQL
  • Network
  • Networking Commands
  • NFS
  • Nginx
  • Nodejs
  • NTP
  • Open Source
  • OpenSUSE
  • Oracle Linux
  • Package Managers
  • Pentoo
  • PHP
  • Podman
  • Postfix Mail Server
  • PostgreSQL
  • Python
  • Questions
  • RedHat
  • Redis Server
  • Rocky Linux
  • Security
  • Shell Scripting
  • SQLite
  • SSH
  • Storage
  • Suse
  • Terminals
  • Text Editors
  • Top Tools
  • Torrent Clients
  • Tutorial
  • Ubuntu
  • Udemy Courses
  • Uncategorized
  • VirtualBox
  • Virtualization
  • VMware
  • VPN
  • VSCode Editor
  • Web Browsers
  • Web Design
  • Web Hosting
  • Web Servers
  • Webmin
  • Windows
  • Windows Subsystem
  • WordPress
  • Zabbix
  • Zentyal
  • Zorin OS
Visits
  • 0
  • 440
  • 579,527

DesignLinux.com © All rights reserved

Go to mobile version