23 C
Jaipur
Friday, November 20, 2020

Advanced Copy – Add Progress Bar To cp And mv Commands In Linux

Must read

gmusicbrowser Music Player Sees First Release In More Than 5 Years

After almost 5 and a half years of no new releases, gmusicbrowser was finally updated. The latest gmusicbrowser 1.1.16 brings support for Opus files, adds...

Google Now Allow To Disable Smart Features and Personalisation

Google can process personal data to allow additional features, such as Google reminders for due bills,...

The GNU cp and GNU mv tools are used to copy and move files and directories in GNU/Linux operating system. One missing feature in these two utilities is they don’t show you any progress bar. If you copy a large file or directory, you really don’t know how long the copy process would take to complete, or the percentage of data copied. You will not see which file is currently being copied, or how many were already copied. All you will see is just the blinking cursor and the hard drive LED indicator. Thanks to Advanced Copy, a patch for Gnu Coreutils, we can now add progress bar to cp and mv commands in Linux and show the progress bar while copying and/or moving large files and directories.

Advanced Copy is a mod for the GNU cp and GNU mv programs. It adds a progress bar and provides some information on what’s going on while you copy or move files and folders. Not only the progress bar, it also shows the data transfer rate, estimated time remaining and the file name that is currently being copied. At the end you will see a short summary on how many files are copied and how long it took to copy the files.

Install ‘Advanced Copy’ Patch To Add Progress Bar To cp And mv Commands in Linux

The cp and mv commands are part of the GNU coreutils. So you need to download the latest GNU coreutils from here.

$ wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz

Extract the downloaded archive using command:

$ tar xvJf coreutils-8.32.tar.xz

This command will extract coreutils archive in a folder named coreutils-8.32 in the current directory. Cd into it:

$ cd coreutils-8.32/

Download the Advanced Copy patch using the following command:

$ wget https://raw.githubusercontent.com/jarun/advcpmv/master/advcpmv-0.8-8.32.patch

Finally, apply the patch by running the following commands one by one:

$ patch -p1 -i advcpmv-0.8-8.32.patch
$ ./configure
$ make

Now two new patched binaries namely cp and mv will be created in the coreutils-8.32/src folder. Just copy them to your $PATH like below:

$ sudo cp src/cp /usr/local/bin/cp
$ sudo cp src/mv /usr/local/bin/mv

That’s it. The cp and mv commands have progress bar functionality now.

Whenever you want a progress bar while copying or moving files and directories, just add -g flag like below:

$ cp -g archlinux.iso mydownload/

Or use --progress-bar flag:

$ cp --progress-bar archlinux.iso mydownload/

Sample output:

Copying at  25.7 MiB/s (about 0h 0m 1s remaining)
archlinux.iso                                                          568.1 MiB / 646.0 MiB
[=========================================================================>                  ] 87.9 %
Add Progress Bar To cp And mv Commands in Linux

At the end of the copy process, you will see how many files were copied, how long it took to copy the file(s), and the data transfer rate per second. Nice, isn’t?

1 files (646.0 MiB) copied in 11.8 seconds ( 54.7 MiB/s).

To copy a directory and its sub-directories recursively, simply add -R flag:

$ cp -gR directory1/ directory2/

Similarly, to move files using mv command, run:

$ mv -g archlinux.iso mydownload/

Or, use --progress-bar flag:

$ mv --progress-bar archlinux.iso mydownload/

To move directories with mv command, use:

$ mv -g directory1/ directory2/

You can also create aliases to save a few key strokes. To do so, edit ~/.bashrc file:

$ nano ~/.bashrc

Add the following lines at the end:

alias cp='/usr/local/bin/cp -gR'
alias mv='/usr/local/bin/mv -g'

Press Ctrl+o and Ctl+x to save and close the file.

Now run the following command to take effect the changes:

$ source ~/.bashrc

From now on, you can just use cp or mv commands without -g (or --progress-bar) flag.

Please note that the original programs are not overwritten. You can still call them at any time via /usr/bin/cp or /usr/bin/mv.

Adding progress bar functionality to cp and mv commands is a good idea if you often copy or move a lot of large files and directories. You can now see what exactly is going on while copying and moving files, instead of staring the screen.

Resources:

Related read:

Source link

- Advertisement -

More articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest article

gmusicbrowser Music Player Sees First Release In More Than 5 Years

After almost 5 and a half years of no new releases, gmusicbrowser was finally updated. The latest gmusicbrowser 1.1.16 brings support for Opus files, adds...

Google Now Allow To Disable Smart Features and Personalisation

Google can process personal data to allow additional features, such as Google reminders for due bills,...