linux下cp和mv命令显示进度条

1.查看当前系统下coreutils工具包的版本号:

[root@k8s-master ~]# rpm -qa | grep -w coreutils
coreutils-8.22-24.el7_9.2.x86_64

当前版本为8.22。

因为cp 和 mv 命令由 coreutils 软件包提供,所以需要重新下载 coreutils 软件包配置补丁

2.下载coreutils安装包

[root@k8s-master ~]# wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz
--2024-05-27 13:28:36--  http://ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz
Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b
Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5547836 (5.3M) [application/x-xz]
Saving to: ‘coreutils-8.32.tar.xz’

100%[=================================================================================================================================================>] 5,547,836   1.05MB/s   in 5.9s   

2024-05-27 13:28:42 (912 KB/s) - ‘coreutils-8.32.tar.xz’ saved [5547836/5547836]

3.下载补丁包

[root@k8s-master ~]# wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz
--2024-05-27 13:28:36--  http://ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz
Resolving ftp.gnu.org (ftp.gnu.org)... 209.51.188.20, 2001:470:142:3::b
Connecting to ftp.gnu.org (ftp.gnu.org)|209.51.188.20|:80... connected.
HTTP request sent, awaiting response... 200 OK
Length: 5547836 (5.3M) [application/x-xz]
Saving to: ‘coreutils-8.32.tar.xz’

100%[=================================================================================================================================================>] 5,547,836   1.05MB/s   in 5.9s   

2024-05-27 13:28:42 (912 KB/s) - ‘coreutils-8.32.tar.xz’ saved [5547836/5547836]

[root@k8s-master ~]# 
[root@k8s-master ~]# wget https://github.com/jarun/advcpmv/archive/refs/heads/master.zip
--2024-05-27 13:29:14--  https://github.com/jarun/advcpmv/archive/refs/heads/master.zip
Resolving github.com (github.com)... 20.205.243.166
Connecting to github.com (github.com)|20.205.243.166|:443... connected.
HTTP request sent, awaiting response... 302 Found
Location: https://codeload.github.com/jarun/advcpmv/zip/refs/heads/master [following]
--2024-05-27 13:29:15--  https://codeload.github.com/jarun/advcpmv/zip/refs/heads/master
Resolving codeload.github.com (codeload.github.com)... 20.205.243.165
Connecting to codeload.github.com (codeload.github.com)|20.205.243.165|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: unspecified [application/zip]
Saving to: ‘master.zip’

    [ <=>                                                                                                                                              ] 87,993       435KB/s   in 0.2s   

2024-05-27 13:29:16 (435 KB/s) - ‘master.zip’ saved [87993]

[root@k8s-master test-cp]# ls
coreutils-8.32.tar.xz  master.zip

4.安装依赖包

[root@k8s-master test-cp]# yum install gcc gcc-c++ unzip patch
Loaded plugins: fastestmirror, langpacks
Determining fastest mirrors
 * base: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
base                                                                                                                                                                | 3.6 kB  00:00:00     
docker-ce-stable                                                                                                                                                    | 3.5 kB  00:00:00     
epel                                                                                                                                                                | 4.3 kB  00:00:00     
extras                                                                                                                                                              | 2.9 kB  00:00:00     
kubernetes                                                                                                                                                          | 1.4 kB  00:00:00     
updates                                                                                                                                                             | 2.9 kB  00:00:00     
(1/3): docker-ce-stable/7/x86_64/primary_db                                                                                                                         | 150 kB  00:00:02     
(2/3): epel/x86_64/updateinfo                                                                                                                                       | 1.0 MB  00:00:02     
(3/3): epel/x86_64/primary_db                                                                                                                                       | 8.7 MB  00:00:08     
Package gcc-4.8.5-44.el7.x86_64 already installed and latest version
Package unzip-6.0-24.el7_9.x86_64 already installed and latest version
Package patch-2.7.1-12.el7_7.x86_64 already installed and latest version
Resolving Dependencies
--> Running transaction check
---> Package gcc-c++.x86_64 0:4.8.5-44.el7 will be installed
--> Processing Dependency: libstdc++-devel = 4.8.5-44.el7 for package: gcc-c++-4.8.5-44.el7.x86_64
--> Running transaction check
---> Package libstdc++-devel.x86_64 0:4.8.5-44.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===========================================================================================================================================================================================
 Package                                           Arch                                     Version                                           Repository                              Size
===========================================================================================================================================================================================
Installing:
 gcc-c++                                           x86_64                                   4.8.5-44.el7                                      base                                   7.2 M
Installing for dependencies:
 libstdc++-devel                                   x86_64                                   4.8.5-44.el7                                      base                                   1.5 M

Transaction Summary
===========================================================================================================================================================================================
Install  1 Package (+1 Dependent package)

Total download size: 8.7 M
Installed size: 25 M
Is this ok [y/d/N]: y
Downloading packages:
(1/2): libstdc++-devel-4.8.5-44.el7.x86_64.rpm                                                                                                                      | 1.5 MB  00:00:02     
(2/2): gcc-c++-4.8.5-44.el7.x86_64.rpm                                                                                                                              | 7.2 MB  00:00:07     
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                                                                      1.2 MB/s | 8.7 MB  00:00:07     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libstdc++-devel-4.8.5-44.el7.x86_64                                                                                                                                     1/2 
  Installing : gcc-c++-4.8.5-44.el7.x86_64                                                                                                                                             2/2 
  Verifying  : gcc-c++-4.8.5-44.el7.x86_64                                                                                                                                             1/2 
  Verifying  : libstdc++-devel-4.8.5-44.el7.x86_64                                                                                                                                     2/2 

Installed:
  gcc-c++.x86_64 0:4.8.5-44.el7                                                                                                                                                            

Dependency Installed:
  libstdc++-devel.x86_64 0:4.8.5-44.el7                                                                                                                                                    

Complete!

5.解压软件包

[root@k8s-master test-cp]# tar -Jxf coreutils-8.32.tar.xz
[root@k8s-master test-cp]# unzip master.zip 
Archive:  master.zip
1e2b1c6b74fa0974896bf94604279a3f74b37a63
   creating: advcpmv-master/
  inflating: advcpmv-master/README.md  
  inflating: advcpmv-master/advcpmv-0.5-8.21.patch  
  inflating: advcpmv-master/advcpmv-0.6-8.24.patch  
  inflating: advcpmv-master/advcpmv-0.7-8.25.patch  
  inflating: advcpmv-master/advcpmv-0.8-8.28.patch  
  inflating: advcpmv-master/advcpmv-0.8-8.30.patch  
  inflating: advcpmv-master/advcpmv-0.8-8.31.patch  
  inflating: advcpmv-master/advcpmv-0.8-8.32.patch  
  inflating: advcpmv-master/advcpmv-0.9-9.0.patch  
  inflating: advcpmv-master/advcpmv-0.9-9.1.patch  
  inflating: advcpmv-master/advcpmv-0.9-9.2.patch  
  inflating: advcpmv-master/advcpmv-0.9-9.3.patch  
  inflating: advcpmv-master/advcpmv-0.9-9.4.patch  
  inflating: advcpmv-master/advcpmv-0.9-9.5.patch  
  inflating: advcpmv-master/install.sh  

6.将补丁包拷贝到coreutils的安装目录下

[root@k8s-master test-cp]# cp advcpmv-master/advcpmv-0.8-8.32.patch coreutils-8.32/
[root@k8s-master test-cp]# ls -la coreutils-8.32/
total 4388
drwxrwxr-x 11 root root    4096 May 27 13:32 .
drwxr-xr-x  4 root root      97 May 27 13:31 ..
-rw-rw-r--  1 root root   93787 Nov 30  2016 ABOUT-NLS
-rw-rw-r--  1 root root   54456 Mar  4  2020 aclocal.m4
-rw-r--r--  1 root root   28676 May 27 13:32 advcpmv-0.8-8.32.patch
-rw-rw-r--  1 root root    3812 Dec 31  2018 AUTHORS
-rwxrwxr-x  1 root root   33544 Jan  1  2020 bootstrap
-rw-rw-r--  1 root root    7638 Feb 25  2020 bootstrap.conf
drwxrwxr-x  2 root root    4096 Mar  5  2020 build-aux
-rw-rw-r--  1 root root   37078 Mar  1  2020 cfg.mk
-rw-rw-r--  1 root root  432030 Mar  5  2020 ChangeLog
-rwxrwxr-x  1 root root 1994671 Mar  5  2020 configure
-rw-rw-r--  1 root root   22928 Feb 28  2020 configure.ac
-rw-rw-r--  1 root root   35149 Mar 17  2019 COPYING
-rw-rw-r--  1 root root    4615 Nov 30  2016 dist-check.mk
drwxrwxr-x  2 root root     210 Mar  5  2020 doc
drwxrwxr-x  5 root root   16384 Mar  5  2020 gnulib-tests
-rw-rw-r--  1 root root    4574 Mar  5  2020 GNUmakefile
-rw-rw-r--  1 root root   20849 Mar  2  2020 init.cfg
-rw-rw-r--  1 root root   15756 Nov 29  2017 INSTALL
drwxrwxr-x  5 root root   20480 Mar  5  2020 lib
drwxrwxr-x  2 root root   12288 Mar  5  2020 m4
-rw-rw-r--  1 root root    1882 May 14  2018 .mailmap
-rw-rw-r--  1 root root   66387 Feb  3  2020 maint.mk
-rw-rw-r--  1 root root    8046 Feb 28  2020 Makefile.am
-rw-rw-r--  1 root root 1112382 Mar  5  2020 Makefile.in
drwxrwxr-x  2 root root    8192 Mar  5  2020 man
-rw-rw-r--  1 root root  216415 Mar  5  2020 NEWS
drwxrwxr-x  2 root root    4096 Mar  5  2020 po
-rw-rw-r--  1 root root       5 Mar 11  2019 .prev-version
-rw-rw-r--  1 root root   10778 Jan  1  2020 README
drwxrwxr-x  3 root root    4096 Mar  5  2020 src
-rw-rw-r--  1 root root       5 Mar  5  2020 .tarball-version
drwxrwxr-x 25 root root    4096 Mar  5  2020 tests
-rw-rw-r--  1 root root   51272 Mar  5  2020 THANKS
-rwxrwxr-x  1 root root     441 May 28  2012 thanks-gen
-rw-rw-r--  1 root root   38355 Feb 28  2020 THANKS.in
-rw-rw-r--  1 root root    2022 Mar  4  2020 THANKS-to-translators
-rw-rw-r--  1 root root     121 Aug 23  2011 THANKStt.in
-rw-rw-r--  1 root root      11 Mar  5  2020 .timestamp
-rw-rw-r--  1 root root    6641 Jan  1  2020 TODO
-rw-rw-r--  1 root root       5 Mar  5  2020 .version
-rw-rw-r--  1 root root    1982 Jan  1  2020 .vg-suppressions

7.使用patch命令加载补丁包

[root@k8s-master test-cp]# cd coreutils-8.32 && patch -p1 -i advcpmv-0.8-8.32.patch
patching file src/copy.c
patching file src/copy.h
patching file src/cp.c
patching file src/mv.c

8.安装coreutils软件包

[root@k8s-master coreutils-8.32]# ./configure FORCE_UNSAFE_CONFIGURE=1
[root@k8s-master coreutils-8.32]# make

9.备份原来的cp和mv命令

[root@k8s-master coreutils-8.32]# cp /usr/bin/cp{,.bak}
[root@k8s-master coreutils-8.32]# cp /usr/bin/mv{,.bak}

10.新增cp和mv命令

[root@k8s-master coreutils-8.32]# src/cp src/cp /usr/bin/cp
[root@k8s-master coreutils-8.32]# src/cp src/mv /usr/bin/mv

11.修改配置文件设置别名

[root@k8s-master coreutils-8.32]# vim /etc/profile
alias cp='cp -ig'
alias mv='mv -ig'


[root@k8s-master coreutils-8.32]# source /etc/profile

12.测试

[root@k8s-master ~]# cp -r test-cp/ /tmp/
4676 folder(s)/file(s) (117.2 MiB) copied in  5.9s ( 17.7 MiB/s).
[root@k8s-master ~]# 

 

评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值