11 ms·
GCP - cp with a progress bar
Nifty, lightweight copy tool. Completely replace cp with: alias cp="/usr/bin/gcp"
- _JamesA_ 13y agoWhy? rsync does all of this and a whole lot more.
- protomyth 13y agoHe didn't want all the complication of rsync, he just wanted something simple with a progress bar. Rsync isn't really that simple. Sure, he could of wrote a shell script on top of rsync, but he probably learned a lot more from this.
- fragmede 13y agoFor local copies, rsync with a progress meter is as simple as rsync --progress <source> <destination>
- johnchristopher 13y agoI usually use it like this for local copy: rsync -rvh --progress <source> <destination>
- elementai 13y agoOh-my-zsh has a plugin 'cp' which is basically an alias: alias cpv="rsync -poghb --backup-dir=/tmp/rsync -e /dev/null --progress --"
- olavgg 13y agoWhen I read the installation example, I see that you also need the python-progressbar library, which means it depends on Python. So I would say rsync is simpler.
- protomyth 13y agoI was thinking (and didn't convey in writing) more on the use side, not the install side. It just bugs me that everything someone gets some joy from trying has a first comment of "why?".
- irahul 13y agoThe "why" generally comes into play when you project it as a solution to an unsolved problem(or at least a problem which can't be easily solved). If you leave it as "because it's fun", I am fine with it. If you present it as "now you can have progress bars with cp", I will ask "why? I can already do that with rsync". That's not because I want to put down your work; that's just thinking out loud.
- protomyth 13y agoI have an honest question then, "What benefit does the why post have?". I can see it if you're trying to warn someone of something, but otherwise it just comes off wrong. If you are going for a teaching moment, then saying "I wanted the same thing and I chose to solve it with rsync with the following alias / script" is better than telling someone they are just a waste of time.
- irahul 13y agoMake what you will of it. I am more likely to phrase it as "Why? rsync works just fine" than ""I wanted the same thing and I chose to solve it with rsync with the following alias / script". FWIW, as far as being educational goes, your phrasing says the same thing with padding. Also, "how" matters only when I have "why" answered. If it isn't mentioned on the project page, or I skim too fast to grasp it, "why" would be the first thing on my mind.
- teh_klev 13y agoAnd therein lies the sickness that is affects HN sometimes. For a bunch of hackers there are some fairly closed off minds. I did think rsync could do this as well, but there are other ways to skin a cat, perhaps not all in the most efficient ways, but what's wrong with exploring doing it this way? As developers and hackers, aren't we supposed to explore and try stuff out? FWIW, I learned some new python odds and sods out of this, even if I don't use this.
- vikas0380 13y agoA good alternative to cp.
- Game_Ender 13y agoFor single files or monitoring other pipe based operations (like network transfers) pv [1] is also a useful tool. 1 - http://www.ivarch.com/programs/pv.shtml http://www.ivarch.com/programs/pv.shtml
- ollybee 13y agoI find pv useful when moving MySQL databases between servers. mysqldump -u user dbname | pv | mysql -u user -h some_remote server dbname
- baiitsu 13y agoUsing pv: gcp() { cat "$1" | pv | cat > "$2" }
- gcmalloc 13y agouseless use of cat pv < "$1" > "$2"
- nitrogen 13y agoEven if the cat at the beginning of a pipe isn't strictly necessary, it still helps readability to have everything flowing from left to right.
- emillon 13y agoI also advocate this "useless" use of cat, but you can write the redirection before the command: <"$1" pv >"$2"
- michaelmior 13y agoThe bigger problem is that using cat destroys the file size information.
- nilved 13y agopv reads content from a file by default, so that can actually be reduced further to: pv "$1" > "$2"
- coherentpony 13y agoThe 'g' prefix is a bad idea. On BSD systems that prefix is used to refer to binaries in the GNU toolset.
- theOnliest 13y agoI'd recommend "pcp," for "progress copy"...I'd use it for the name alone!
- 2bluesc 13y agoSCP works locally too and has a progress bar.
- rquirk 13y agoscp just falls back to cp when copying locally, so doesn't show any progress bar.
- k_bx 13y agoIf you use oh-my-zsh, gcp is binded to "git cherry-pick" (with auto-completion etc.), so I did: sudo ln -s /usr/bin/gcp /usr/local/bin/cp_
- ck2 13y agoI think someone made a patch which works with the original gnu coreutils Oh here it is http://beatex.org/web/advancedcopy.html http://beatex.org/web/advancedcopy.html
- mhugo 13y agoThis one is also pretty clever (based on catching the write() syscall with strace) : https://chris-lamb.co.uk/posts/can-you-get-cp-to-give-a-progress-bar-like-wget https://chris-lamb.co.uk/posts/can-you-get-cp-to-give-a-prog...
- lamby 13y agoThanks.
- Zecc 13y agoThis seems relevant: http://www.commandlinefu.com/commands/view/4553/copy-a-file-using-dd-and-watch-its-progress http://www.commandlinefu.com/commands/view/4553/copy-a-file-... dd does not show a progress bar, unfortunately but it does report its progress.
- joelthelion 13y agoShouldn't cp have "-h" (human readable) flag that does exactly that?
- paranoiacblack 13y agoIn what world does "-h" default to "human readable"?
- icebraining 13y agoUNIX Style, or cat -v Considered Harmful: http://harmful.cat-v.org/cat-v/ http://harmful.cat-v.org/cat-v/
- joelthelion 13y agoThat's not an argument. There's no reason why cp shouldn't report progress if you want to. Not one.