How can I make a progress bar while copying a dire

2019-01-16 06:45发布

I suppose I could compare the number of files in the source directory to the number of files in the target directory as cp progresses, or perhaps do it with folder size instead? I tried to find examples, but all bash progress bars seem to be written for copying single files. I want to copy a bunch of files (or a directory, if the former is not possible).

10条回答
爷、活的狠高调
2楼-- · 2019-01-16 07:02

You may have a look at the tool vcp. Thats a simple copy tool with two progress bars: One for the current file, and one for overall.

EDIT

Here is the link to the sources: http://members.iinet.net.au/~lynx/vcp/ Manpage can be found here: http://linux.die.net/man/1/vcp

Most distributions have a package for it.

查看更多
\"骚年 ilove
3楼-- · 2019-01-16 07:11

There's a tool pv to do this exact thing: http://www.ivarch.com/programs/pv.shtml

There's a ubuntu version in apt

查看更多
Fickle 薄情
4楼-- · 2019-01-16 07:12

A simple unix way is to go to the destination directory and do watch -n 5 du -s . Perhaps make it more pretty by showing as a bar . This can help in environments where you have just the standard unix utils and no scope of installing additional files . du-sh is the key , watch is to just do every 5 seconds. Pros : Works on any unix system Cons : No Progress Bar

查看更多
戒情不戒烟
5楼-- · 2019-01-16 07:16

How about something like

find . -type f | pv -s $(find . -type f | wc -c) | xargs -i cp {} --parents /DEST/$(dirname {})

It finds all the files in the current directory, pipes that through PV while giving PV an estimated size so the progress meter works and then piping that to a CP command with the --parents flag so the DEST path matches the SRC path.

One problem I have yet to overcome is that if you issue this command

find /home/user/test -type f | pv -s $(find . -type f | wc -c) | xargs -i cp {} --parents /www/test/$(dirname {})

the destination path becomes /www/test/home/user/test/....FILES... and I am unsure how to tell the command to get rid of the '/home/user/test' part. That why I have to run it from inside the SRC directory.

查看更多
【Aperson】
6楼-- · 2019-01-16 07:18

Here another solution: Use the tool bar

You could invoke it like this:

#!/bin/bash
filesize=$(du -sb ${1} | awk '{ print $1 }')
tar -cf - -C ${1} ./ | bar --size ${filesize} | tar -xf - -C ${2}

You have to go the way over tar, and it will be inaccurate on small files. Also you must take care that the target directory exists. But it is a way.

查看更多
贼婆χ
7楼-- · 2019-01-16 07:21

You can also use rsync instead of cp like this:

rsync -Pa source destination

Which will give you a progress bar and estimated time of completion. Very handy.

查看更多
登录 后发表回答