1

I need to copy huge files in my Linux machine.

Example:

cp source.txt target.txt

I want to create bar progress that will show that copy still in progress on each copy file

Examples"

cp file file1

copy file > file1 .........

cp moon mars

copy moon > mars .......

yael
  • 13,106

2 Answers2

7

In short, you won't find cp native functionality for progress bar output. Why? Many reasons. However, you have some options:

  1. Use a different tool. rsync, as mentioned by @user1404316 has --progress:

    rsync -P largeFile copyLocation
    
  2. If you don't need the extra semantics that cp and rsync take care of, create a new file with pv ("Pipe Viewer") by redirecting stdout:

    pv < largeFile > copyLocation
    
  3. If you do need the extra semantics, you can use progress, though it doesn't give the bar specifically. It attaches to already running processes, so you would invoke it like:

    # In one shell
    $ cp largeFile copyLocation
    
    # In another shell
    $ progress -m
    [ 4714] cp /home/hunteke/largeFile
            1.1% (114 MiB / 10.2 GiB)      # -m tells progress to continually update
    
  4. Another option is gcp, which does exactly what you've requested with a progress bar:

    gcp largeFile copyLocation
    
  5. Another option abuses curl's ability to handle file:// urls:

    curl -o copyLocation file:///path/to/largeFile
    
  6. You can write a shell script

hunteke
  • 211
  • 1
    why not use like this pv largeFile > copyLocation ( not as mentioned pv < largeFile > copyLocation ) – yael Feb 27 '18 at 06:13
  • regarding the gcp , I not found for centos – yael Feb 27 '18 at 06:16
  • @yael mild semantic difference. Yours will continue where a previous copy left off. The mentioned version mimics cp's standard overwrite behavior. – hunteke Feb 27 '18 at 06:19
  • I download the pv , and I see that copy is very fast it take much less then cp , so my question is dose pv copy the source to target with high reliability – yael Feb 27 '18 at 06:20
  • Not knowing your exact command, I'm surprised at the speed difference. The underlying mechanism doing the copying in both cases is the kernel. cp may be doing some extra CRC or other checks, but I doubt it. What cp will do that pv won't, especially with -a, is maintain stat properties, like time modified, ownership (if you're running as root), etc. – hunteke Feb 27 '18 at 06:24
1

rsync is a copy program that has great features for copying huge files, including a --progress feature, and it has a form of in-transit compression to reduce the data in transit (and thus saving time for the copy):

rsync --progress file1 file2

rsync also has features to resume a copy that was interrupted, maybe due to a network disconnection. You would need to start it with options --partial --append-verify. The only downside that I can think of to using rsync for copying over a network is that it needs to have been installed on both computers, ie. the sender and the receiver. See its man page for details and all its other features...

If you can't install rsync for some reason, or don't want to, a good simple alternative is pv, a pipe viewer command, that does exactly what you are asking for.

pv from-file > to-file

pv also includes many visualization options. See its man page for all the goodies available. Here are some of the commonly used options:

-p, --progress
-t, --timer
-e, --eta
-r, --rate
-a, --average-rate
-b, --bytes
user1404316
  • 3,078
  • pv is great , can we say that pv is affected exactly like cp? or cp -r or cp -rp ? – yael Feb 27 '18 at 05:11
  • I'm not sure I understand your comment. They are different commands, so no, options specific to cp won't exist for pv unless the man page for pv says so. – user1404316 Feb 27 '18 at 05:24