Can you get cp to give a progress bar like wget?
chris-lamb.co.uk
chris-lamb.co.uk
size=`wc -c a` ; cp a b & sleep 1 ; ETA 'wc -c b' $size
Every 10 seconds it runs the given command, then gives an ETA to the number you want. It's not a progress bar, but it is a projected time of completion and can easily be extended if you want.http://news.ycombinator.com/item?id=1149364
ETA is like pv but for those occasions when you don't have access to the data stream in a pipe. It can be used anytime you can compute a number that indicates how far along you are. Just give it the command to run for itself, or run the command and feed the values to ETA on stdin and it will give you regular estimates of when it will hit the given target.
It also lets your cp run at full speed, unlike when you copy through pv, and is more generic than just checking on the progress of specifically a copy command. It lets you predict the completion time of anything measurable.
cp a b
run pv < a > b*Hmmm, I can't back up my own predictions:
cp huge blah 0.11s user 7.94s system 6% cpu 2:12.54 total
pv < huge > something 0.12s user 8.10s system 7% cpu 1:54.86 total #!/usr/bin/env python
from sys import argv
from subprocess import Popen
copy_from = open(argv[-2],'r')
copy_to = open(argv[-1],'w')
Popen("pv", stdin=copy_from, stdout=copy_to)
copy_from.close()
copy_to.close()
Just alias cp to it in Bash.Still, nice pointer to the pv tool, which I hadn't heard of.
Still still, the linked awk snipped is awfully clever and more fun to read.
My team and I use a hack which overrides cd and as well as calling builtin cd it sources a script if it exists from cwd. This means you can get the exact enviroment you need for that working copy of a project.
cp() { pv < $1 > $2; }
(Or name the function something else if you want regular cp still available.) sudo port install pv
"just works" :-) (Well, assuming you use MacPorts anyway.)In the BUGS section of the man page you can find these items (amongst others):
A traced process ignores SIGSTOP except on SVR4 platforms.
Hmm. That's useful to note. A traced process which tries to block SIGTRAP will be sent
a SIGSTOP in an attempt to force continuation of tracing.
I can understand that, although it could be surprising in practice for the unwary. A traced process runs slowly.
Understandable. Traced processes which are descended from command may be
left running after an interrupt signal (CTRL-C).
That's definitely worth knowing. On Linux, exciting as it would be, tracing the init process
is forbidden.
Damn.But of course, nothing is stopping you from commenting this check out.
I was thinking of slowing the copy operation down a bit more by roundtripping it through Australia...
cp $SOURCE /dev/stdout | pv | cp /dev/stdin $DEST
Edit: "pv <a >b" is simpler, but isn't the game to fit "cp" somewhere? :)
$ rsync --progress file1 file2