How to Show Progress Bar for Rsync Command While Copying Files
For Linux new user, if you want to upload or download files from/to the remote system, you can use the Rsync command or SCP command to achieve the result. And is it possible to show the progress for Rsync command while coping files in your Linux terminal. How to show Total progress bar while coping files using Rsync Linux command.
Rsync is a widely-used utility to keep copies of a file on two computer systems the same. It is commonly found on Unix-like systems and functions as both a file synchronization and file transfer program. The rsync algorithm, a type of delta encoding, is used to minimize network usage.
Show Progress Bar Using Rsync Command
If you want to show progress bar while coping files using Rsync command, you need to use the -P or –progress option to show progress during file transfer. And the basic syntax for rsync command is:
rsync -P source_files destination_file
Or
rsync –progress source_files destination_file
If you want to copy a file from the current directory to another directory using rsync command, just issue the following command:
$ rsync -P testRsync.zip /tmp
Outputs:
root@devops-VirtualBox:/home/devops# rsync -P testRsync.zip /tmp testRsync.zip 306,118,656 58% 146.03MB/s 0:00:01
If you want to copy files from your local system to a remote server called: osetc.com, just using the following command:
$ rsync -av -P testRsync.zip abc@osetc.com:/tmp/
Outputs:
root@devops-VirtualBox:/home/devops# rsync -av -P testRsync.zip abc@osetc.com:/tmp/ sending incremental file list testRsync.zip 5,734,400 1% 94.65kB/s 1:31:18
You can also use PV command to monitor the progress of rsync command, you need to redirect the output of rsync command to pv command, and the pv command will create a dialog progress bar.
Firstly, you need to install pv package on your Linux system, just type the following command:
$ sudo apt install pv (For Debian or ubuntu system)
Or
$ sudo yum install pv (For CentOS or RHEL system)
Outputs:
root@devops-VirtualBox:/home/devops# apt install pv Reading package lists... Done Building dependency tree Reading state information... Done Suggested packages: doc-base The following NEW packages will be installed: pv 0 upgraded, 1 newly installed, 0 to remove and 16 not upgraded. Need to get 48.3 kB of archives. After this operation, 123 kB of additional disk space will be used. Get:1 http://mirrors.aliyun.com/ubuntu bionic/main amd64 pv amd64 1.6.6-1 [48.3 kB] Fetched 48.3 kB in 0s (167 kB/s) Selecting previously unselected package pv. (Reading database ... 174912 files and directories currently installed.) Preparing to unpack .../archives/pv_1.6.6-1_amd64.deb ... Unpacking pv (1.6.6-1) ... Setting up pv (1.6.6-1) ... Processing triggers for man-db (2.8.3-2ubuntu0.1) ...
Then you can use Rsync command in combination with PV command to copy files. Assuming that you want to copy 4000 files from the current directory to /tmp directory, just using the following command:
$ rsync -vrltD /home/devops/Python-3.7.3/* | pv -lep -s 4000
Outputs:
Python/thread_nt.h Python/thread_pthread.h Python/traceback.c Python/wordcode_helpers.h Python/clinic/ Python/clinic/_warnings.c.h Python/clinic/bltinmodule.c.h Python/clinic/context.c.h Python/clinic/import.c.h Python/clinic/marshal.c.h Python/clinic/sysmodule.c.h Python/clinic/traceback.c.h m4/ m4/ax_check_openssl.m4 sent 78,131,291 bytes received 69,986 bytes 22,343,222.00 bytes/sec total size is 77,891,019 speedup is 1.00 [====================================================================================================================> ] 95%
Conclusion
You should know that how to use Rsync command to show total progress while copying a large size files in Linux terminal.