45

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

hairboat
  • 2,903
  • 18
  • 51
  • 72
daviesgeek
  • 38,901
  • 52
  • 159
  • 203

4 Answers4

66

You can use rsync instead.

rsync --progress /copy/from /copy/to
bahamat
  • 3,535
  • 1
    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
  • 4
    Using rsync -P /copy/from /copy/to is equivalent to rsync --partial --progress /copy/from /copy/to which will display the copy progress, as well as resume the transfer if it is disconnected. – gh0st Jul 21 '17 at 16:03
  • 2
    And just like cp, it needs the -r flag to make it not skip directories – Alexander May 22 '19 at 15:36
45

During cp, CtrlT displays the current percentage (on macOS at least)

Allan
  • 101,432
Vamos
  • 551
  • that's awesome! – felix021 Jun 13 '18 at 02:57
  • 5
    The reason this works is because Ctrl-t sends SIGINFO signals in the same way that Ctrl-c sends SIGINT signals. You can e.g. use a loop in another shell to repeatedly kill -INFO the process in question if you don't want to keep pressing the keys. Because it's a signal, it works with other utilities too, e.g. dd. Ctrl-t and SIGINFO are inherited from BSD. – HTNW Sep 03 '18 at 01:35
2

If you are copying large files or directories using cp, you can open up 'Activity Monitor', go to the 'Disk' tab and look for the process 'cp'. Here you can keep track of how many bytes have been written since the last boot, giving you a rough idea of the progress. (OS X 10.10).

Hope that helps!

Franz
  • 121
  • 1
0
#!/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..

Essobi
  • 111