How to Show Progress Bar for Linux Commands

progress bar linuxMany Linux commands like dd, cp, rsync, and mv are progressive, but have no progress bars showing as they run. There is not built in way to check the progress of ongoing operations. In this article, we’ll look at certain Linux tools and options which allow you to monitor the progress of data being transferred.

1) PV Command

Pv is command line - based tool that allows you to monitor the progress of data being transferred using pipe. The pv command gives you a visual view of the following information.

  • Time elapsed
  • Percentage completed using a progress bar.
  • Current throughput rate.
  • Total data transferred.
  • ETA (Estimated Time).

Installing Pv

You can install pv on your distro using the following commands

Fedora, CentOS and RHEL

# yum install pv

Debian, Ubuntu and Linux Mint

# apt-get install pv

Gentoo Linux

# emerge --ask sys-apps/pv

FreeBSD Linux

# cd /usr/ports/sysutils/pv/
# make install clean

Pv Usage with Examples

The general syntax for pv is pv [Options] [File]

The -p switch turns the progress bar on, -t switch activates the total elapsed time pv has been running for, the -e switch provides the ETA to completion based on the transfer rate and data size, the -r switch shows the current rate of the transfer and finally the -b switch shows the total amount of data transferred so far.

Monitor the progress of creating an archive using gzip

In this example, we use pv with gzip in the following example:

pv -tpre ~/Desktop/testfile.iso | gzip > ~/Desktop/testfile.gz
213MiB 0:00:14 [17.8MiB/s] [=========> ] 32% ETA 0:00:29

In this example, we provide the switches and the file in question, and then pipe it to gzip with a redirection to the file we want to archive.

Monitor the progress when copying a file with pv

$ pv ~/Desktop/testfolder/* > ~/Desktop/

667MiB 0:00:13 [50.5MiB/s] [================================>] 100%

Using pv without any switches will automatically run with the default pte,r and b switches.

Using pv and dialog commands to create a dialog progress bar

pv ~/Desktop/testfile.iso > ~/Desktop/destinationfile.iso | dialog --gauge "Progress" 10 70

2) Progress

Progress, formerly known as cv, is a tool which displays the percentage of copied data from coreutils basic commands like p, mv, dd, tar, gzip/gunzip, cat, etc. It can also provide additional information such as ETA and throughout.

Installing Progress

You can install progress on any distro with these steps.

sudo apt-get install libncurses5-dev (for Debian/Ubuntu) users.
# git clone https://github.com/Xfennec/progress.git
# make
# make install

Progress Usage with Examples

The general syntax for progress is watch progress -q. This lets you monitor all current and upcoming transfers in a terminal window. Now, any coreutils utility you invoke like cp and mv will be detected and indicated in the progress window.

Monitoring Downloads

progress -wc google-chrome

The -c switch can be used to monitor a command name like google-chrome or firefox

3) Rsync

Rsync is used to sync files locally and remotely. Rsync can be used to copy files and also has the ability to show the progress without the use on an external application.

Installing Rsync

Fedora, CentOS and RHEL

# yum install rsync

Debian, Ubuntu and Linux Mint

# apt-get install rsync

Rsync Usage with Examples

You need to use rsync with the -P or --progress option to show progress during file transfer. The basic syntax for rsync is

rsync --progress source destination

Or

rsync -P source destination

To copy a zip file from the desktop to newfolder, enter:

$ rsync -P ~/Desktop/myfiles.zip ~/Desktop/newfolder
 321,683,456 45% 3.17MB/s 0:01:56

To copy files from a /example/*.tar to a remote server called [email protected], enter:

rsync -av -P /example/*.tar [email protected]:~

4) Advanced Copy

Advanced Copy, or advcpmv, is a mod for the cp and mv utilities which adds a progress bar and provides some information on ongoing transferred.

Installing Advanced Copy

You can install progress on any distro with these steps.

# wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.21.tar.xz
# tar xvJf coreutils-8.21.tar.xz
# cd coreutils-8.21/
# wget https://github.com/atdt/advcpmv/blob/master/advcpmv-0.5-8.21.patch
# patch -p1 -i advcpmv-0.5-8.21.patch
# ./configure
# make

You might get this error, while running “./configure” command.

checking whether mknod can create fifo without root privileges... configure: error: in `/home/xxx/coreutils-8.21': configure: error: you should not run configure as root (set FORCE_UNSAFE_CONFIGURE=1 in environment to bypass this check) See `config.log' for more details

Run the following command to fix that error and rerun the ./configure command again:

# export FORCE_UNSAFE_CONFIGURE=1

Replace the original cp and mv commands with these two new commands

# cp src/cp /usr/local/bin/cp
# cp src/mv /usr/local/bin/mv

Advanced Copy Usage with Examples

The cp and mv commands stay same, the only change is adding the -g or -progress-bar switch to the cp command. The -R switch is used to copy directories recursively. Here is an example of the command:

$ cp -gR /home/linoxide /home/linoxide/Desktop

Or

# cp -R --progress-bar home/linoxide /home/linoxide/Desktop

We’ve seen a couple tools and how they can be used to monitor progress on commands. The pv command is easy to setup and can monitor any command line activity. The progress utility is limited to only coreutils commands. Rsync has the inbuilt ability to monitor file transfers and advanced copy is a patch applied to only the cp and mv commands to show progress. Based on your trial, you can decide which of these is best for you.

About Eyram Amedzor

Kwaku Eyram has been a working with computers and software for more than 10 years. He's an all-round geek and very fluid with Linux, Android and Windows operating systems. Asides being a tech enthusiast, Kwaku doubles as a tech support personnel and a tech writer. He currently has interest in IoT, web development and information security.

Author Archive Page

Have anything to say?

Your email address will not be published. Required fields are marked *

All comments are subject to moderation.