Add a Progress Bar to Linux Commands Using Advanced Copy

Display A Progress Bar In The Terminal While Copying And Moving Files!

The cp command in Linux is a very nice program which is used to copy files and directories from one location to another. Similarly, the mv command can be used to move and rename files from one location to another. Both the commands are part of GNU CoreUtils and is available on every Linux distribution.

However, these commands lack some features which, although is not a huge deal, can be easily implemented by the developers.

One such feature is a progress bar.

Unless you use the verbose flag (-v) with these commands, there is no other way through which you can know how much your transfer has progressed. And even the verbose option can be a real mess if you have to move a lot of files.

Advanced copy is a mod for the GNU cp and mv commands, which simply adds a progress bar to all the transfers done by them. In this tutorial, I will show you how to install and use the Advanced copy and move tool on your system, and also create a bash alias to make its usage easier.

Installing Advanced Copy

This tool is not available in any of the Linux distribution’s repository, so we will have to build it from source. Just make sure that you have the curl and patch command installed on your system (and if it is not installed, you can install it using your distribution’s package manager) and run the following script from your Terminal:

curl https://raw.githubusercontent.com/jarun/advcpmv/master/install.sh --create-dirs -o ./advcpmv/install.sh && (cd advcpmv && sh install.sh)
The Script Will Automatically Install Advcp Command
The Script Will Automatically Install Advcp Command

If you encounter any error regarding running this command without root privileges, you can first run the following command before building from the script:

export FORCE_UNSAFE_CONFIGURE=1

Tweaks and Usage

The commands were added in ./advcpv directory, which is not added to our $PATH. You can either add this directory to $PATH or simply move the files to /usr/local/bin directory. You can do this by typing the following commands:

sudo mv ~/advcpmv/advcp /usr/local/bin/cpg
sudo mv ~/advcpmv/advmv /usr/local/bin/mvg
Moving The Commands In Bin Diectory
Moving The Commands In Bin Directory

Finally, you can add bash aliases in your Bashrc file so that the terminal always uses the advmv and advcp files instead of mv and cp respectively. Type:

echo alias cp=''/usr/local/bin/advcp -g' >> ~/.bashrc'
echo alias mv=''/usr/local/bin/advmv -g' >> ~/.bashrc'
Make Terminal Aliases For Better Usage
Make Terminal Aliases For Better Usage

The second command in this screenshot tells the terminal to read all the configs we have set in bashrc file. You do not have to type the command though, you can just close your Terminal and reopen it. Finally, try moving or copying a file like you normally do.

Progress Bar Is Now Visible While Copying A File
Progress Bar Is Now Visible While Copying A File

If you want to copy/move a directory recursively, you can use the -R flag along with the command like this:

advcp -gR path/to/source /path/to/destination
Copying Directories Using Advanced Copy
Copying Directories Using Advanced Copy

If you do not find these commands helpful, then you can always just delete the /usr/local/advcp and /usr/local/advmv files to uninstall Advanced Copy. You can also call the original cp and mv commands by typing /usr/bin/cp and /usr/bin/mv.

Summary

Advanced copy seems to be an awesome extension to the cp and mv commands. And it is really sad that the progress bar feature will be not up streamed into the cp and mv commands because the GNU coreutils team feel that the cp and mv commands are feature complete.

I also feel that adding this command in the official repositories will give people more exposure to it, as not every is going to build it from source just to display a progress bar. Also note that the script mentioned above does not add any documentation for itself in the ‘man’ command, so you have to rely on the cp or mv command’s manual entry or go through their GitHub page to learn more about it.

References

Advanced Copy – ADVCP GitHub repository