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).

share|improve this question
11  
You've hit Bash FAQ # 44. Take a look and see if any of the suggestions there are useful. – jw013 Aug 20 '11 at 0:47

To add another option, you can use cpv. It uses pv to imitate the usage of cp.

It works like pv but you can use it to recursively copy directories

enter image description here

You can get it here

share|improve this answer

How about something like

find . -type f | pv -s $(find . -type f | wc -c) | xargs -i cp {} --parents /DEST/$(dirname {})

It finds all the files in the current directory, pipes that through PV while giving PV an estimated size so the progress meter works and then piping that to a CP command with the --parents flag so the DEST path matches the SRC path.

One problem I have yet to overcome is that if you issue this command

find /home/user/test -type f | pv -s $(find . -type f | wc -c) | xargs -i cp {} --parents /www/test/$(dirname {})

the destination path becomes /www/test/home/user/test/....FILES... and I am unsure how to tell the command to get rid of the '/home/user/test' part. That why I have to run it from inside the SRC directory.

share|improve this answer

My preferred option is Advanced Copy, as it uses the original cp source files.

$ wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.21.tar.xz
$ tar xvJf coreutils-8.21.tar.xz
$ cd coreutils-8.21/
$ wget --no-check-certificate https://raw.githubusercontent.com/atdt/advcpmv/master/advcpmv-0.5-8.21.patch
$ patch -p1 -i advcpmv-0.5-8.21.patch
$ ./configure
$ make

The new programs are now located in src/cp and src/mv. You may choose to replace your existing commands:

$ sudo cp src/cp /usr/local/bin/cp
$ sudo cp src/mv /usr/local/bin/mv
share|improve this answer
    
The link to the patch at zwicke.org is broken but it's on github at github.com/atdt/advcpmv. Perhaps someone with more skills than I will update @elboletaire's steps. – Setaa Feb 8 '17 at 21:43
    
I can do it, thanks for the links to the patch – elboletaire Feb 8 '17 at 22:19

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.

share|improve this answer
5  
Right, rsync --progress /path/to/origin /path/to/destination is awesome and is available on all systems. – Adrien Nov 10 '13 at 18:32
    
Works when copying a single file as well. – Nathan Jan 15 '14 at 19:04
    
Happen to know the speed comparison between rsync and cp? – Allasso Feb 1 '16 at 21:16
    
@Allasso Tough to say because there's so many options and situations which affect it. It can be slower for certain sets files, especially with a small CPU, because it's analyzing/syncing not copying, and encrypting files (when over a network, iirc). For example see superuser.com/questions/109780/how-to-speed-up-rsync or superuser.com/questions/153176/… – SteveLambert Feb 15 '16 at 17:48

A simple unix way is to go to the destination directory and do watch -n 5 du -s . Perhaps make it more pretty by showing as a bar . This can help in environments where you have just the standard unix utils and no scope of installing additional files . du-sh is the key , watch is to just do every 5 seconds. Pros : Works on any unix system Cons : No Progress Bar

share|improve this answer

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
share|improve this answer
1  
gcp is Python-based. PLEASE DO NOT USE IN PRODUCTION. I did not check, but it seems does not support hardlinks, special attributes and so on . – socketpair Oct 1 '16 at 12:56

There's a tool pv to do this exact thing: http://www.ivarch.com/programs/pv.shtml

There's a ubuntu version in apt

share|improve this answer

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.

share|improve this answer
    
I was hoping for something that doesn't require compiling external tools. I just want to see my directory get copied. Is it really so difficult? – octosquidopus Aug 20 '11 at 0:21
    
@Anonymouse added a second answer, maybe this would be an alternative for you. But thats my last idea :( – Thomas Berger Aug 20 '11 at 0:48
1  
As said below, rsync is available on all systems (even Mac OS), as opposed to vcp. – Adrien Nov 10 '13 at 18:32
1  
The members.iinet.net.au/~lynx/vcp link is broken. There seems to be a current fork at github.com/gdm85/curses-vcp with a last commit of May 29, 2016. I was able to compile it just fine on Fedora 23. An independent vcp with a similar concept is at github.com/lynix/vcp but I have not tried it. – Setaa Feb 8 '17 at 21:14

Here another solution: Use the tool bar

You could invoke it like this:

#!/bin/bash
filesize=$(du -sb ${1} | awk '{ print $1 }')
tar -cf - -C ${1} ./ | bar --size ${filesize} | tar -xf - -C ${2}

You have to go the way over tar, and it will be inaccurate on small files. Also you must take care that the target directory exists. But it is a way.

share|improve this answer
    
Early on, I thought about tarring the folder before moving it, but thought it would lack too much in elegance. I was wrong. It works as expected and might actually be a better solution in some cases. Thanks! – octosquidopus Aug 20 '11 at 1:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.