Pipe viewer¶
![Pipe viewer](http://www.ivarch.com/programs/images/pv.png)
This morning, quite in a hurry, I just wanted to clean up my USB stick before rushing to work. And as always when you’re in a rush it takes forever until it finishes. If it finishes at all.
My problem was that I didn’t know how long it would take until the files have been copied or moved and I had to wait in front of the monitor. Instead I could have done something else and come back to it later when the task had finished.
Now the _pain_ had become strong enough and I decided to fix this issue. Once and for all.
A bit of research and I found the tool pipe viewer.
One way of copying a single file would be like this:
$ pv <file> > <destination>/<file>
The tools isn’t quite intuitive at a first glance, but let me help out here:
It works basically like cat.
Since I wasn’t the first one with this problem, I quickly stumbled over several solutions and scenarios where pipe viewer could be use: compressing, copying, decompressing, bla, bla, bla. Since copying and moving was the only thing I’m interested in I found this code snipped on Commandlinefu:
# http://www.commandlinefu.com/commands/view/6862/function-for-copy-files-with-progress-bar-using-pv-pipe-viewer Link
cp_p() {
if [ `echo "$2" | grep ".*\/$"` ]; then
pv "$1" > "$2""$1";
else
pv "$1" > "$2"/"$1";
fi
}
It works great for one file and fails when handling multiple. But I need it for several files, preferably working as similar as possible to the copy and move commands I’m used to. So I took the freshly gained knowledge and put everything in a small shell script.
Well, that seems to work.