Take the 2-minute tour ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Is is possible to display a progress bar when copying files in Terminal using cp?

share|improve this question
2  
…you could also consider using rsync instead. –  Asmus Jul 28 '11 at 19:25

2 Answers 2

up vote 17 down vote accepted

You can use rsync instead.

rsync --progress /copy/from /copy/to
share|improve this answer
    
Thanks you very much! –  daviesgeek Jul 29 '11 at 17:07
    
Speedwise, which is faster, rsync or cp? –  daviesgeek Jul 29 '11 at 17:08
    
If all files being copied do not exist in the destination I don't think there will be a noticeable difference. If some of the files do exist in the destination then it will vary because rsync does some checking. Rsync will usually (but not always) be faster in that case. –  bahamat Jul 29 '11 at 17:11
    
Ok, thanks so much! –  daviesgeek Jul 29 '11 at 17:34
#!/bin/sh
   strace -q -ewrite cp -- "${1}" "${2}" 2>&1 \
      | awk '{
        count += $NF
            if (count % 10 == 0) {
               percent = count / total_size * 100
               printf "%3d%% [", percent
               for (i=0;i<=percent;i++)
                  printf "="
               printf ">"
               for (i=percent;i<100;i++)
                  printf " "
               printf "]\r"
            }
         }
         END { print "" }' total_size=$(stat -c '%s' "${1}") count=0

It's not perfect, but it works... drop that in a directory path and name it something similar..

share|improve this answer
    
Wait...how do I get that to run??? –  daviesgeek Jul 29 '11 at 17:07
1  
I don't recall whether OS X had an strace command at the time this answer was written (July 2011), but it definitely doesn't today. –  APDent Sep 4 '13 at 21:11

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.