Home > System Tutorial > LINUX > Linux command artifact - the wonderful use of cp and mv

Linux command artifact - the wonderful use of cp and mv

PHPz
Release: 2024-02-10 15:30:24
forward
970 people have browsed it

In the Linux operating system, file management is one of the most common operations. The commonly used cp and mv commands, as file copy and move tools in Linux, have always been one of the most familiar commands to Linux users. But beyond basic copy and move operations, what other uses do these two commands have? Let's explore together.

This article mainly introduces how to use the open source project advcpmv on Github to implement the progress bar of the "cp" and "mv" commands in Linux.

Linux command artifact - the wonderful use of cp and mv
Since the cp and mv commands both belong to the coreutils tool package, our main operation is to add patches when compiling coreutils to implement the progress bar function.

# 注意尽量不要使用 root 用户操作
$ pwd
/home/tinychen

# 下载coreutils
$ wget http://ftp.gnu.org/gnu/coreutils/coreutils-8.32.tar.xz
$ tar -xJf coreutils-8.32.tar.xz
$ cd coreutils-8.32/

# 下载 github 上的补丁
$ wget https://raw.githubusercontent.com/jarun/advcpmv/master/advcpmv-0.8-8.32.patch
# 打补丁,实现进度条显示
$ 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

# 编译安装
$ ./configure
$ make
# 将打补丁生成的cp和mv命令的二进制文件复制到bin目录下
$ sudo cp src/cp /usr/local/bin/cp
$ sudo cp src/mv /usr/local/bin/mv
Copy after login

Then we only need to add the -g parameter when using the cp and mv commands to display the progress bar. For convenience, we can set alias in the .bashrc file

$ alias cp='cp -ig'
$ alias mv='mv -ig'
Copy after login

Try the actual effect. When copying a large folder, the total progress and current file copy progress can be displayed. After the copy is completed, the average speed during the copy process can also be displayed.

$ cp -r /samba/Elements02/kvm/* /kvm/

0 files copied so far...               
                                                                                                                  
    1.6 GiB /  67.2 GiB
[===>                                                                                                                                                                 
  ]  2.4 %
Copying at 178.4 MiB/s (about 0h 6m 45s remaining)
/samba/Elements02/kvm/iso/CentOS-6.10-x86_64-bin-DVD1.iso                                                                                                 
   1.6 GiB /   3.7 GiB
[========================================================================>
Copy after login

Linux command artifact - the wonderful use of cp and mv
Linux command artifact - the wonderful use of cp and mv

In short, cp and mv, as flexible tools in Linux file management, have a variety of powerful usages and can greatly improve the work efficiency and convenience of Linux users. This article introduces only part of them, and there are many advanced uses waiting for readers to explore. In daily use, mastering these two commands can allow us to manage various files in the Linux system more efficiently.

The above is the detailed content of Linux command artifact - the wonderful use of cp and mv. For more information, please follow other related articles on the PHP Chinese website!

source:lxlinux.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template