Move files in bash with tar and progress bar
Example
gas@caldaia ~ $ my_move source_dir/ dest_dir/
43.5GB at 61.0MB/s eta: 59s 91% [=========== ]
You need to install “command line progress bar”, in gentoo it can be installed with emerge bar in ubuntu the deb can be grabbed here and installed with gdebi.
my_move:
#! /bin/sh
SOURCE="$1"
DEST="$2"
SIZE=$(du -sb "$SOURCE"|awk '{print $1}')
(cd "$SOURCE" && tar -cf - *)|bar -s $SIZE| (cd "$DEST" && tar -xBpf -)
see-also:
[I] sys-apps/pv
Available versions: 1.1.4 {debug nls}
Installed versions: 1.1.4(02:54:46 PM 08/30/2010)(nls -debug)
Homepage: http://www.ivarch.com/programs/pv.shtml
Description: Pipe Viewer: a tool for monitoring the progress of data through a pipe
Smorg
11 set 10 at 17:04
Very nice, thanks. Have you thought about using rsync instead of tar? rsync works well as an improved copy command. I’m not sure how you would get passwords into the pipe for the nifty progress bar but it would be nice to be able to copy over a network like this.
twitter
12 set 10 at 17:11
Isn’t this more like a copy since tar doesn’t remove the source? It’s also good practice to quote $SOURCE and $DEST.
Ewoud Kohl van Wijngaarden
15 set 10 at 04:47
for such things i like to use
rsync -av –progress src/ dst/
flux
20 set 10 at 23:15