Home  >  Article  >  Computer Tutorials  >  How to display the progress bar in linux cp command

How to display the progress bar in linux cp command

王林
王林forward
2024-03-23 20:41:441456browse

1. Background

When using the cp command to copy large files in Linux, it is usually impossible to view the copy progress in real time. This situation may make people feel anxious because there is no way to know the progress of the copy. However, you can use some techniques to add a visual progress bar to the cp command so that users can clearly see the progress of the copy.

2. Compile

We use open source projects: advcpmv

The github address is:

https://github.com/jarun/advcpmv

You can directly use the following command to compile and install (non-root) and execute it in the Linux environment. I use the CentOS operating system to demonstrate here:

curl https://raw.githubusercontent.com/jarun/advcpmv/master/install.sh --create-dirs -o ./advcpmv/install.sh && (cd advcpmv && sh install.sh)

linux cp命令怎么显示进度条

If you need to execute it under the root user, add environment variables before the downloaded installation script

FORCE_UNSAFE_CONFIGURE=1 ./install.sh

After the script ends, it will look like the following picture:

linux cp命令怎么显示进度条

# 显示当前目录下已经编译好的文件
cd advcpmv && ls

linux cp命令怎么显示进度条

3. Installation and use

Use the following command to install and use:

sudo mv ./advcp /usr/local/bin/advcp
sudo mv ./advmv /usr/local/bin/advmv

Test copy:

advcp -g 源文件 目标位置

Found that the progress bar has appeared successfully:

linux cp命令怎么显示进度条

If you want to directly replace the original cp and mv commands, you can use aliases:

echo alias cp '/usr/local/bin/advcp -g' >> ~/.bashrc
echo alias mv '/usr/local/bin/advmv -g' >> ~/.bashrc

4. Summary

If there is a need to frequently copy large files in the company, this command can be integrated into the Linux system command of the production environment for direct use.

The above is the detailed content of How to display the progress bar in linux cp command. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:mryunwei.com. If there is any infringement, please contact admin@php.cn delete