In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-30 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
This article focuses on "how to add a progress bar to Linux's cp and mv commands". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to add a progress bar to Linux's cp and mv commands.
Cp and mv are probably one of the most frequently used Linux commands in your daily life. However, a prominent problem is that neither of these commands will have any prompts, which can only be done when manipulating large files. You may be used to this, but there is also a solution. In this article, we introduce a patch Advanced Copy of Gnu Coreutils (the source package of cp and mv) to add a progress bar to it.
Advanced Copy is the cp and mv program mod. By adding a progress bar to cp and mv, it provides information such as the progress bar, the data transfer rate, the estimated remaining time and the file name currently being manipulated during file (folder) copy or move operations. Finally, an information summary of the operation is provided showing how many files the operation has taken and how long the operation has taken.
Installation
Download the source code
The cp and mv commands are part of GNU coreutils. In order to add plug-ins to it, you need to download the source code and compile and install it.
We can download coreutils from GNU's software ftp or through the source code Git repository cgit, or mirror stations gitweb and GitHub. The latest version is 8.32.
Curl-O ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz
Use the following command to extract the source package:
Tar xvJf coreutils-8.32.tar.xz
In this way, all the source code will be extracted into the coreutils-8.32 folder.
Cd coreutils-8.32/
Add an Advanced Copy patch to it (download github:jarun/advcpmv from the github repository):
Add a patch
For the downloaded patch pack, use the following command to patch:
Patch-p1-I.. / advcpmv/advcpmv-0.8-8.32.patch
Compile
Run the compiler to compile the patched source directory
. / configure make
When the compilation is complete, the application cp and mv are generated in the folder of the compiled directory coreutils-8.32/src.
Use
Increase system path
Simply copy them to the system's $PATH, as follows:
Sudo cp src/cp / usr/local/bin/cp sudo cp src/mv / usr/local/bin/mv
In this way, the cp and mv commands come with the function of a progress bar. You need a progress bar when copying or moving files and directories, just add the-g parameter or the-- progress-bar flag:
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%
At the end of the replication process, you can see how many files have been copied, how long it took to copy the files, and the data transfer rate per second.
1 files (305.0 MiB) copied in 1.8 seconds (172.2 MiB/s)
To copy a directory and its subdirectories recursively, simply add-Rflag:
Cp-gR directory1/ directory2/
Similarly, to move a file using the mv command, run:
Mv-g archlinux.iso mydownload/
Or, use the-- progress-bar flag:
Mv-progress-bar archlinux.iso mydownload/
To move a directory using the mv command, also use the-g argument:
Mv-g directory1/ directory2/
Add alias
You can also create aliases to save some buttons. Edit the ~ / .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 to save and close the file.
Now run the source command to make the changes take effect immediately:
Source / .bashrc
In this way, the command for the-g (or-- progress-bar) flag is attached by default in cp or mv, without the need to manually increase the flag.
To use programs without precision bars by default, you can use / usr/bin/cp or / usr/bin/mv.
Summary
Adding progress bars to cp and mv operations is a very useful feature if you copy or move many large files and directories frequently. In this article, we introduced an Advanced Copy patch to implement this feature, which allows me to keep abreast of the operation, rather than waiting there.
At this point, I believe you have a better understanding of "how to add a progress bar to Linux's cp and mv commands". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.