nixCraft Poll

Topics

Shell Scripting Hack: cp Command With a Progress bar

Posted by Vivek Gite [Last updated: January 24, 2008]

This is a nice shell scripting hack. It allows you to give a progress bar like wget to cp command.

Want to stay up to date with the latest Linux tips, news and announcements? Subscribe to our free e-mail newsletter or RSS feed to get all updates. You can Email this page to a friend.

You may also be interested in other helpful articles:

Discussion on This Article:

  1. mastrboy Says:

    great script function, i have tried something like it before called bar: http://www.theiling.de/projects/bar.html

  2. vivek Says:

    masterboy,

    bar - great find!

  3. unixfoo Says:

    This is a good one ..

    - http://unixfoo.blogspot.com

  4. drivesoslow Says:

    It won’t do anything for me. I try to use it and it just come right back to the prompt.

  5. Jerod Says:

    drivesoslow:

    same here :(

  6. vivek Says:

    drivesoslow / Jerod ,

    Open a shell prompt and just paste the code. Type the following (it will not work with wildcards)
    cp_p /path/to/big/file.ext /copy/here

  7. Jeff Schroeder Says:

    Vivek,

    This is cool and all, but the overhead of strace make this not very useful. rsync -av shows a progress bar. You can also get a progress bar if you use scp locally. Yes, scp supports local file transfers without using any network or connecting to a local sshd instance.

    jeff@omniscience:~$ du -h windows.tar.bz2
    822M windows.tar.bz2
    
    jeff@omniscience:~$ time cp_p windows.tar.bz2{,.new}
    99% [====================================================================================================>]
    
    real 2m18.957s
    user 0m11.589s
    sys 0m23.469s
    jeff@omniscience:~$ ls window*
    windows.tar.bz2 windows.tar.bz2.new
    jeff@omniscience:~$ time cp windows.tar.bz2{,.new2}
    
    real 1m39.597s
    user 0m0.096s
    sys 0m5.092s
  8. Sadphuck Says:

    ahh…. doesn’t work for me either dude. this totally sucks.. phuck this… dont waste ur time. I wanna crap on u so hard dude.

  9. Daemones Says:

    How i can use this script?

  10. Buddy Friend Says:

    LOL at the nubs who can’t get this to work. Go back to your Vista box and stay there.

    Only thing I had to do was set my terminal to ANSI. Also, the width of this progress bar is fixed, it will not scale with the width of your terminal.

    Also note that for trivial transfers they might complete before the script has a chance to output the progress bar. So if the file copies and you didn’t see a progress bar, it’s because you didn’t need one.

    yes scp and rsync are alternatives but this is very cool nonetheless. Thank you for posting it!

Leave a Reply

We encourage your comments, and suggestions. But please stay on topic, be polite, and avoid spam. Thank you very much for stopping by our site!

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Tags: , ,

Copyright © 2004-2008 nixCraft. All rights reserved - TOS/Disclaimer - Privacy policy - Sitemap - Powered by Open source software.