Is this possible?
-
2Interesting that this is marked as a duplicate of a question asked 3 years later? – Chris Oct 10 '18 at 19:53
5 Answers
The standard coreutils cp
command doesn't support this. There's a Gentoo patch floating around that adds it for different versions, although it's not included in Gentoo anymore for some reason; the version for coreutils 6.10 is in their bugzilla, and I'm sure there are lots of others around.
If you don't want to patch cp
, you need to use some other command. For example, rsync
has a --progress
flag, so you can do:
rsync --progress source destination
If instead of copying you cat the data and then redirect stdout to the destination (i.e. cat source > destination
), then you can use a program that measures pipe throughput and insert it in the middle (cat source | SOME-PROGRAM > destination
); there are a couple mentioned in this related question. The one I recommended there was pv (Pipe Viewer):
If you give it the --rate
flag it will show the transfer rate

- 93,103
- 40
- 240
- 233
-
Very interesting, although not worth the effort. I merely would like cp
to provide a rate similar to how it would report transfer rate using the GUI. Not worth the effort to type that much text just to see the transfer speed. Thanks though. -
8@Chris Well, you can always add a function for it.
function cprate() {cat "$1" | pv --rate > "$2"}
– Michael Mrozek Oct 28 '10 at 14:45 -
pv
seems good, but I tried it for the same reason as the poster (progress/rate when copying to nfs), where the file gets crated in tmp and transferred afterwards. So, instead of nfs I have to use smb to see progess and rates. – Mar 11 '12 at 15:45 -
1Using "cat" is a very dangerous method, I have experienced that cat on some AIX Systems will cut out what they interpret as garbage. Depending on the character set you chose by default. I would agree totally with rsync! – Oliver Aug 13 '14 at 13:31
I find that using pv in this manner works well for that purpose
pv -p file1 > file2
The -p
switch shows the file transfer progress. To see the transfer speed, add the -r
switch. If you want to see the average transfer rate over time, you can use the -a
switch.
pv -pra file1 > file2

- 125
-
1
-
3
pv
is Pipe Viewer, and is pretty awesome. @Patrick, please expand your post with an explanation. – Stefan Lasiewski Oct 29 '10 at 18:55 -
2This is the same command I mentioned in my answer, although I didn't realize it takes a filename argument (I did
cat file | pv
) – Michael Mrozek Oct 30 '10 at 01:31 -
Good explanation: http://www.catonmat.net/blog/unix-utilities-pipe-viewer/ – Kijewski Nov 25 '11 at 01:40
-
It seems to measure only the read speed and not the write speed, as it writes only to cache (even for a several GB sized file) – Mark Jeronimus Jul 13 '20 at 08:21
I know this is rather old, but...
If you do not actually want to display the rate, but only want to watch if something is happening on copying of a large file, you can also just use the watch
command (also works with mv
):
cp /path/to/myfile /path/to/target/myfile
Then, in another shell, or pushing the copy-command to the background (e.g. with Ctrl + Z
followed by bg
), you can check the result with:
watch "ls -sh1 /path/to/target"
This will continuously update the output of the ls
command update (by default every 2.0s), displaying something like:
Every 2.0s: ls -sh1 /path/to/target
Tue Jan 12 15:02:45 2016
total 1.1G
4.0K data
130M tmp1.txt
137M tmp2.txt
151M tmp3.txt
168M tmp4.txt
162M myFile

- 201
-
1This is a neat hack. Although mine shows Every 2s. And I don't think it is accurate. – GeneCode Mar 22 '18 at 05:54
-
Thanks - if we have already started the command this really is the only way to avoid checkign the file size manually every few secs :) – SidJ Sep 26 '18 at 06:48
-
-
@GeneCode -n switch in the watch command allows to set the update interva in secondsl (also fractions like 0.5 are usually possible). the -h in the ls command makes output "human readable"... you can leave that out if you want byte counts :-) – muelleth Sep 26 '18 at 07:17
Hi Another way to show the transfer speed is to use scp
on localhost like this:
scp -rv src_folder user@localhost:/dest_folder

- 181
Here is a script that uses du
to monitor throughput. This is more application agnostic and is also referenced in https://unix.stackexchange.com/a/301490/183269. Execute the script on the destination host.
monitorio () {
# show write speed for file or directory
interval="10"
target="$1"
size=$(du -ks "$target" | awk '{print $1}')
firstrun="1"
echo ""
while [ 1 ]; do
prevsize=$size
size=$(du -ks "$target" | awk '{print $1}')
#size=$(ls -l "$1" | awk '{print $5/1024}')
kb=$((${size} - ${prevsize}))
kbmin=$((${kb}* (60/${interval}) ))
kbhour=$((${kbmin}*60))
# exit if this is not first loop & file size has not changed
if [ $firstrun -ne 1 ] && [ $kb -eq 0 ]; then break; fi
echo -e "\e[1A $target changed ${kb}KB ${kbmin}KB/min ${kbhour}KB/hour size: ${size}KB"
firstrun=0
sleep $interval
done
}
example use:
user@host:~$ dd if=/dev/zero of=/tmp/zero bs=1 count=50000000 &
user@host:~$ monitorio /tmp/zero
/tmp/zero changed 4KB 24KB/min 1440KB/hour size: 4164KB
/tmp/zero changed 9168KB 55008KB/min 3300480KB/hour size: 13332KB
/tmp/zero changed 9276KB 55656KB/min 3339360KB/hour size: 22608KB
/tmp/zero changed 8856KB 53136KB/min 3188160KB/hour size: 31464KB
^C
user@host:~$ killall dd; rm /tmp/zero