Is is possible to display a progress bar when copying files in Terminal using cp?
Asked
Active
Viewed 6.5k times
45
4 Answers
66
You can use rsync instead.
rsync --progress /copy/from /copy/to
bahamat
- 3,535
-
1
-
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
-
4Using
rsync -P /copy/from /copy/tois equivalent torsync --partial --progress /copy/from /copy/towhich will display the copy progress, as well as resume the transfer if it is disconnected. – gh0st Jul 21 '17 at 16:03 -
2And just like cp, it needs the
-rflag to make it not skip directories – Alexander May 22 '19 at 15:36
45
-
-
5The reason this works is because
Ctrl-tsendsSIGINFOsignals in the same way thatCtrl-csendsSIGINTsignals. You can e.g. use a loop in another shell to repeatedlykill -INFOthe 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-tandSIGINFOare 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
-
-
2I don't recall whether OS X had an
stracecommand at the time this answer was written (July 2011), but it definitely doesn't today. – Tim Ruddick Sep 04 '13 at 21:11 -
rsyncinstead. – Asmus Jul 28 '11 at 19:25