by Linux Of cp and mv Command to add a progress bar

 by Linux Of cp and mv Command to add a progress bar

 

cp and mv It's probably the one you use most in your daily life Linux Command one . But there is an outstanding problem that neither command has any prompt message , This can only be done when operating large files . Maybe you're used to it , But actually there are solutions , In this article, we will introduce a Gnu Coreutils(cp and mv Source code package for ) Patch for Advanced Copy, It is used to add a progress bar to it .

Advanced Copy yes cp and mv Program mod. It works by giving cp and mv Added a progress bar , File in progress ( clip ) Provide a progress bar for copy or move operations , Data transfer rate , Estimated remaining time and currently operating file name and other information . Last , And how long it will take for an operation summary to display information .

install

Download the source code

cp and mv The order is GNU coreutils Part of . To add plug-ins to it , Need to download the source code and compile the installation .

We can GNU Software for ftp download coreutils Or through the source code Git Warehouse cgit, Or mirror station gitweb and GitHub download , The latest version is 8.32.

curl -O  ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz

 by Linux Of cp and mv Command to add a progress bar

 

Use the following command to unzip the source package :

tar xvJf coreutils-8.32.tar.xz

So all the source code will be unzipped to coreutils-8.32 In the folder .

cd coreutils-8.32/

Add to it Advanced Copy Patches ( adopt github Warehouse downloading github:jarun/advcpmv):

Add patches

For downloaded patches , Use the following command to patch :

patch -p1 -i ../advcpmv/advcpmv-0.8-8.32.patch

compile

Run the compiler , Compile the patched source directory

./configure
make

After compiling, in the compilation Directory coreutils-8.32/src The application will be generated in the folder of cp and mv.

Use

Add system path

Just copy them to the system's $PATH in , As shown below :

sudo cp src/cp /usr/local/bin/cp
sudo cp src/mv /usr/local/bin/mv

such cp and mv The command comes with the function of progress bar . You need a progress bar when copying or moving files and directories , Just add -g Parameters or --progress-bar sign :

cp -g archlinux.iso mydownload/
cp --progress-bar archlinux.iso mydownload/

You can display the progress bar :

 

Copying at 25.7 MiB/s (about 0h 0m 1s remaining)

archlinux.iso 568.1 MiB / 646.0 MiB

[=========================================> ] 87.9 %

 by Linux Of cp and mv Command to add a progress bar

 

At the end of the replication process , You can see how many files have been copied , How long does it take to copy files and the data transfer rate per second .

1 files (305.0 MiB) copied in 1.8 seconds (172.2 MiB/s)

To recursively copy a directory and its subdirectories , Just add -Rflag:

cp -gR directory1/ directory2/

Again , To use mv Command to move files , Please run :

mv -g archlinux.iso mydownload/

perhaps , Use --progress-bar sign :

mv --progress-bar archlinux.iso mydownload/

To use mv Command move Directory , Also use -g Parameters :

mv -g directory1/ directory2/

Add alias

You can also create aliases to save some keys . edit ~/.bashrc file :

vim ~/.bashrc

Add the following line at the end :

alias cp='/usr/local/bin/cp -gR'
alias mv='/usr/local/bin/mv -g'

Press Shift+zz Save and close file .

Now run source Command to make the change take effect immediately :

source ~/.bashrc

In this way cp or mv By default, it comes with -g( or --progress-bar) The order of the sign , Instead of manually adding the flag .

To use the default program without a precision bar , Can pass /usr/bin/cp or /usr/bin/mv Just use it .

summary

If you often copy or move many large files and directories ,cp and mv The function of adding progress bar in operation is very useful . In this article we introduce a Advanced Copy Patches are used to implement this function , Let me know the operation at any time , It's not where you wait .