News for hackers. Stuff that matters.
Re:Can you get cp to give a progress bar like wget? by RiderOfGiraffes on Thursday March 04, 2010 @06:02AM (#1166621)

  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.

Re:Can you get cp to give a progress bar like wget? by gommm on Thursday March 04, 2010 @07:16AM (#1166710)
Thanks! that looks useful... I completely missed your submission the first time you posted it
Re:Can you get cp to give a progress bar like wget? by RiderOfGiraffes on Thursday March 04, 2010 @07:22AM (#1166720)
Re:Can you get cp to give a progress bar like wget? by panic on Thursday March 04, 2010 @05:17AM (#1166569)
Easier: install Pipe Viewer (http://www.ivarch.com/programs/pv.shtml) and, instead of

  cp a b
run

  pv < a > b
Re:Can you get cp to give a progress bar like wget? by __david__ on Thursday March 04, 2010 @06:50AM (#1166666)
I love pv. It's great because it's pretty much a drop-in for "cat" that gives you fancy progress bars. But for copy I tend to use "rsync -aP". It has progress but not a bar and just feels more like a replacement for cp to me.
Re:Can you get cp to give a progress bar like wget? by philjackson on Thursday March 04, 2010 @06:48AM (#1166663)
I like pv and find myself using it when bziping large files (where the blocker is bzip). It must have a negative impact on the speed of a copy.

*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
Re:Can you get cp to give a progress bar like wget? by w1ntermute on Thursday March 04, 2010 @12:38PM (#1167471)
For those of you interested in making it a permanent replacement for cp, you can use this Python script:

    #!/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.
Re:Can you get cp to give a progress bar like wget? by rntz on Thursday March 04, 2010 @01:01PM (#1167535)
Alternatively, you could just write a shell function:

   cp() { pv < $1 > $2; }
(Or name the function something else if you want regular cp still available.)
Re:Can you get cp to give a progress bar like wget? by olliesaunders on Thursday March 04, 2010 @01:58PM (#1167711)
Quote the variables.
Re:Can you get cp to give a progress bar like wget? by rntz on Friday March 05, 2010 @03:22PM (#1170388)
Ah, good point. I'm personally used to zsh, which doesn't have that particular misfeature.
Re:Can you get cp to give a progress bar like wget? by ajross on Thursday March 04, 2010 @12:46PM (#1167493)
Um... in what universe would you want an interactive terminal gadget to become the default implementation of cp? Yikes.

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.

Re:Can you get cp to give a progress bar like wget? by philjackson on Thursday March 04, 2010 @01:48PM (#1167683)
What? I think the override is fine in an interactive environment.

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.

Re:Can you get cp to give a progress bar like wget? by petercooper on Friday March 05, 2010 @12:13AM (#1168883)
Mac users will be happy to learn that:

  sudo port install pv
"just works" :-) (Well, assuming you use MacPorts anyway.)
Re:Can you get cp to give a progress bar like wget? by RiderOfGiraffes on Thursday March 04, 2010 @07:15AM (#1166706)
This item has prompted me to investigate the strace command. It's one to put in the bag of things to try on occasion to make sure I don't forget it.

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.
Re:Can you get cp to give a progress bar like wget? by jrockway on Friday March 05, 2010 @06:38PM (#1170807)
On Linux, exciting as it would be, tracing the init process is forbidden.

But of course, nothing is stopping you from commenting this check out.

Re:Can you get cp to give a progress bar like wget? by yellowbkpk on Thursday March 04, 2010 @06:34AM (#1166652)
I use rsync --progress as a cp replacement when I feel like I need to know how the cp is going.
Re:Can you get cp to give a progress bar like wget? by erso on Thursday March 04, 2010 @10:27PM (#1168741)
I use rsync -avzP exclusively now over cp ever since I tried copying ~7000 files from a USB drive and found cp choked less than 10% through. rsync is wonderful.
Re:Can you get cp to give a progress bar like wget? by leif on Friday March 05, 2010 @02:34AM (#1169009)
The -z flag to rsync is not always the best choice, specifically when copying within one machine.
Re:Can you get cp to give a progress bar like wget? by lamby on Thursday March 04, 2010 @06:57AM (#1166675)
If you feel the need to point out an alternative solution, then I think you have missed the entire point by a wide margin.
Re:Can you get cp to give a progress bar like wget? by metabrew on Thursday March 04, 2010 @07:01AM (#1166683)
Nice hack. Hacks involving strace and awk are fun, the only thing that could have improved this is to somehow involve netcat too.
Re:Can you get cp to give a progress bar like wget? by Estragon on Thursday March 04, 2010 @08:42AM (#1166860)
...somehow involve netcat too.

I was thinking of slowing the copy operation down a bit more by roundtripping it through Australia...

Re:Can you get cp to give a progress bar like wget? by jimbokun on Thursday March 04, 2010 @09:55AM (#1167044)
I think the people pointing out an alternative solution are just trying to join in the fun.
Re:Can you get cp to give a progress bar like wget? by shykes on Thursday March 04, 2010 @05:18AM (#1166571)
Or you could just do:

cp $SOURCE /dev/stdout | pv | cp /dev/stdin $DEST

Edit: "pv <a >b" is simpler, but isn't the game to fit "cp" somewhere? :)

Re:Can you get cp to give a progress bar like wget? by RiderOfGiraffes on Thursday March 04, 2010 @06:35AM (#1166653)
That doesn't give you a progress bar because it doesn't know how big the data stream will be. You need to pass in some options to pv to give it that information.
Re:Can you get cp to give a progress bar like wget? by freshprince on Thursday March 04, 2010 @05:30AM (#1166580)
And now enjoy copying files at only half the usual speed.
Re:Can you get cp to give a progress bar like wget? by khill on Thursday March 04, 2010 @09:03AM (#1166916)
A watched progress bar never reaches 100%.
Re:Can you get cp to give a progress bar like wget? by eru on Thursday March 04, 2010 @11:40AM (#1167304)
I have a screenshot with one that reached 139%.
Re:Can you get cp to give a progress bar like wget? by gwern on Thursday March 04, 2010 @11:45AM (#1167320)
Some distributions of 'cp' have it built in: https://bugs.launchpad.net/fedora/+source/coreutils/+bug/640...
Re:Can you get cp to give a progress bar like wget? by tesseract on Thursday March 04, 2010 @12:35PM (#1167459)
On some BSDs (including Mac OS X) there is a signal, SIGINFO, to which cp will respond by printing out a status report. You can send this signal by typing ^T.
Re:Can you get cp to give a progress bar like wget? by icco on Thursday March 04, 2010 @12:40PM (#1167475)
Ya. I was also thinking of just coding it and submitting a patch...
Re:Can you get cp to give a progress bar like wget? by tzury on Thursday March 04, 2010 @10:06AM (#1167068)
can also with

    $ rsync --progress file1 file2
Re:Can you get cp to give a progress bar like wget? by volomike on Friday March 05, 2010 @12:45AM (#1168916)
I like your way best.
Re:Can you get cp to give a progress bar like wget? by sabat on Thursday March 04, 2010 @03:39PM (#1167965)
rsync -Pv from-file to-file