cp command process info

10,690

Solution 1

You can pipe things into the pv command to add progress indication to programs that might not have their own progress meter.

cp -a source/ dest/ | pv

However if I'm doing a copy large enough that I need a progress bar I end up using rsync anyway as Jeremy recommends. He also points out that you'll need to arrange your pipeline so that the data is piped though pv - the example gives only tells you how much data the cp is printing out, not how much is being copied. Something like this will work for single files: pv source > dest.

However, for copying directories, you'll need to get more complex.

Solution 2

You can use rsync to do the copy. If you use the -P option (show progress), it does just that.

I tend to use rsync -avP <source> <dest> for most copying.

Share:
10,690

Related videos on Youtube

phwd
Author by

phwd

Updated on September 17, 2022

Comments

  • phwd
    phwd over 1 year

    Is there any specific package for cp command which shows the process of being copied.

    I'm wondering if there is any package cp which shows additional information that what has been copied and what are left or how many percentage it has been copied...etc. Any body using any?

  • phwd
    phwd about 13 years
    Yeah you are right and I'll use that for synchronization but the problem is with me as I'm called mistake maker. In hurry, if I exchange soruce with destination or vise versa then I'm done. I seldom use rysnc until it's necessary and I'll have to be very careful. Good answer, thanks!
  • phwd
    phwd about 13 years
    A problem with apt-update 0% [Waiting for headers], once installed pv I'll get back here again.
  • djeikyb
    djeikyb about 13 years
    How is making a mistake with rsync any worse than making a mistake with cp?
  • phwd
    phwd about 13 years
    @djeikyb: what if you specify source in place of destination when using rsync?
  • phwd
    phwd about 13 years
    @djeikyb: what happens if you do the same with cp?
  • Jeremy Kerr
    Jeremy Kerr about 13 years
    If you want to use pv, you'll need to arrange your pipeline so that the data is piped though pv - the example Jorge gives only tells you how much data the cp is printing out, not how much is being copied. Something like this will work for single files: pv source > dest. However, for copying directories, you'll need to get more complex.
  • djeikyb
    djeikyb about 13 years
    If there are no files matching the command, they both fail. If there are files matching the command, they both overwrite. Correct?
  • phwd
    phwd about 13 years
    @djeikyb: Yes, you know better than what I know as I said I'm a mistake maker I try to be at the safer side. But I feel, completely not using rsync is worst using linux
  • phwd
    phwd about 13 years
    @Jeremy Kerr: +1 for more information
  • djeikyb
    djeikyb about 13 years
    shrugs Up to you. I like rsync because it has built-in progress information, and built in copy verification. If you make a mistake, they both have the same consequences.
  • Jorge Castro
    Jorge Castro about 13 years
    @Jeremy Thanks for the info, I've added it into my answer, feel free to propose an edit if there's anything else you'd like clarified.
  • sobi3ch
    sobi3ch over 10 years
    Maybe the best solution is to just extend original cp command with progress options? github.com/goj/coreutils/blob/rm-d/src/cp.c