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:23

My preferred option is Advanced Copy, as it uses the original cp source files.

$ wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.21.tar.xz
$ tar xvJf coreutils-8.21.tar.xz
$ cd coreutils-8.21/
$ wget --no-check-certificate https://raw.githubusercontent.com/atdt/advcpmv/master/advcpmv-0.5-8.21.patch
$ patch -p1 -i advcpmv-0.5-8.21.patch
$ ./configure
$ make

The new programs are now located in src/cp and src/mv. You may choose to replace your existing commands:

$ sudo cp src/cp /usr/local/bin/cp
$ sudo cp src/mv /usr/local/bin/mv
查看更多
放荡不羁爱自由
3楼-- · 2019-01-16 07:25

To show a progress bar while doing a recursive copy of files & folders & subfolders (including links and file attributes), you can use gcp (easily installed in Ubuntu and Debian by running "sudo apt-get install gcp"):

gcp -rf SRC DEST

Here is the typical output while copying a large folder of files:

Copying 1.33 GiB  73% |#####################      | 230.19 M/s ETA:  00:00:07

Notice that it shows just one progress bar for the whole operation, whereas if you want a single progress bar per file, you can use rsync:

rsync -ah --progress SRC DEST
查看更多
放我归山
4楼-- · 2019-01-16 07:25

To add another option, you can use cpv. It uses pv to imitate the usage of cp.

It works like pv but you can use it to recursively copy directories

enter image description here

You can get it here

查看更多
▲ chillily
5楼-- · 2019-01-16 07:25

Check the source code for progress_bar in the below git repository of mine

https://github.com/Kiran-Bose/supreme

Also try custom bash script package supreme to verify how progress bar work with cp and mv comands

Functionality overview

(1)Open Apps ----Firefox ----Calculator ----Settings

(2)Manage Files ----Search ----Navigate ----Quick access

            |----Select File(s)
            |----Inverse Selection
            |----Make directory
            |----Make file
                                          |----Open
                                          |----Copy
                                          |----Move
                                          |----Delete
                                          |----Rename
                                          |----Send to Device
                                          |----Properties

(3)Manage Phone ----Move/Copy from phone ----Move/Copy to phone ----Sync folders

(4)Manage USB ----Move/Copy from USB ----Move/Copy to USB

查看更多
登录 后发表回答