Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make a progress bar while copying a directory with cp?

I suppose I could compare the number of files in the source directory to the number of files in the target directory as cp progresses, or perhaps do it with folder size instead? I tried to find examples, but all bash progress bars seem to be written for copying single files. I want to copy a bunch of files (or a directory, if the former is not possible).

like image 432
octosquidopus Avatar asked Aug 19 '11 23:08

octosquidopus


People also ask

Can cp command Show Progress?

While it doesn't display speed, when copying multiple files, the -v option to the cp command will provide you with progress info.

How do I copy progress bar in Linux?

pv Command You can use the “pv” command for copying a single file as it provides statistics related to the progress and speed. In the following case, “pv” will output the “inputfile” to “stdout”, which is then redirected to the “outputfile” using the “>”operator.

Can you copy a directory using cp command?

In order to copy a directory on Linux, you have to execute the “cp” command with the “-R” option for recursive and specify the source and destination directories to be copied.

Which of the following option is used for directory copying with cp command?

Copying Directories with cp Command To copy a directory, including all its files and subdirectories, use the -R or -r option.


3 Answers

You can also use rsync instead of cp like this:

rsync -Pa source destination

Which will give you a progress bar and estimated time of completion. Very handy.

like image 137
SteveLambert Avatar answered Sep 24 '22 12:09

SteveLambert


To show a progress bar while doing a recursive copy of files & folders & subfolders (including links and file attributes), you can use gcp (easily installed in Ubuntu and Debian by running "sudo apt-get install gcp"):

gcp -rf SRC DEST

Here is the typical output while copying a large folder of files:

Copying 1.33 GiB  73% |#####################      | 230.19 M/s ETA:  00:00:07

Notice that it shows just one progress bar for the whole operation, whereas if you want a single progress bar per file, you can use rsync:

rsync -ah --progress SRC DEST
like image 36
Shervin Emami Avatar answered Sep 22 '22 12:09

Shervin Emami


You may have a look at the tool vcp. Thats a simple copy tool with two progress bars: One for the current file, and one for overall.

EDIT

Here is the link to the sources: http://members.iinet.net.au/~lynx/vcp/ Manpage can be found here: http://linux.die.net/man/1/vcp

Most distributions have a package for it.

like image 30
Thomas Berger Avatar answered Sep 24 '22 12:09

Thomas Berger