Format:
Rsync -- delete-before-a-H-v -- progress -- stats
Option:
-- Delete-before: the receiver is deleted before transmission.
-Progress displays the transmission process during transmission
-A indicates that files are transmitted recursively and all file attributes are maintained.
-R recursively processes subdirectories.
-H: Keep hard-connected files
-V detailed output mode
Example:
/Home/aniya/is an empty folder [no sub-directories or files]. There are many files in the/home/zhaoyj directory. Now you need to clear N files in this directory.
[Root @ XKWB5705 home] # rsync -- delete-before-a-H-v -- progress -- stats/home/aniya // home/zhaoyj
Building file list...
13 files to consider
./
. Bash_history
2032 100% 0.00kB/s 0:00:00 (xfer #1, to-check = 11/13)
. Bash_logout
33 100% 8.06kB/s 0:00:00 (xfer #2, to-check = 10/13)
. Bash_profile
176 100% 21.48kB/s 0:00:00 (xfer #3, to-check = 9/13)
. Bashrc
124 100% 15.14kB/s 0:00:00 (xfer #4, to-check = 8/13)
. Viminfo
557 100% 45.33kB/s 0:00:00 (xfer #5, to-check = 7/13)
. Mozilla/
. Mozilla/extensions/
. Mozilla/plugins/
Maildir/
Maildir/cur/
Maildir/new/
Maildir/tmp/
Number of files: 13
Number of files transferred: 5
Total file size: 2922 bytes
Total transferred file size: 2922 bytes
Literal data: 2922 bytes
Matched data: 0 bytes
File list size: 297
File list generation time: 0.022 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 3513
Total bytes encoded ed: 178
Sent 3513 bytes encoded ed 178 bytes 7382.00 bytes/sec
Total size is 2922 speedup is 0.79
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------
If the source and target files are inconsistent in nature, an error is returned:
[Root @ XKWB5705/] # rsync -- delete-before-a-H-v -- progress -- stats/varOLD // aniya/usr.tar.gz
Building file list...
1 file to consider
ERROR: cannot overwrite non-directory with a directory
Rsync error: errors selecting input/output files, dirs (code 3) at main. c (488) [runner ER = 2.6.8]
Rsync: connection unexpectedly closed (8 bytes encoded Ed so far) [sender]
Rsync error: error in rsync protocol data stream (code 12) at io. c (463) [sender = 2.6.8]
[Root @ XKWB5705/] # ls-l aniya/
Total 1049844
-Rw-r -- 1 root 1073982015 Sep 15 21:09 usr.tar.gz
Certificate ---------------------------------------------------------------------------------------------------------------------------------------------
Haha.txt is an empty file, and usr.tar.gzis a compressed package of 1.1g. now, the size of usr.tar.gz is changed from 1.1G to 0]
[Root @ XKWB5705/] # touch/varOLD/hahaha.txt
[Root @ XKWB5705/] # rsync -- delete-before-a-H-v -- progress -- stats/varOLD/haha.txt/aniya/usr.tar.gz
Building file list...
1 file to consider
Hahah
0 100% 0.00kB/s 0:00:00 (xfer #1, to-check = 0/1)
Number of files: 1
Number of files transferred: 1
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 32
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 90
Total bytes encoded ed: 42
Sent 90 bytes converted ed 42 bytes 88.00 bytes/sec
Total size is 0 speedup is 0.00
Usr.tar.gz does not exist. Check whether the result exists, but the package size is changed to 0.
[Root @ XKWB5705/] # ls-l/aniya/
Total 0
-Rw-r -- 1 root 0 Sep 15 21:22 usr.tar.gz
Certificate -----------------------------------------------------------------------------------------------------------------------------------------------
Now clear the file in/varOLD and make it an empty directory:
[Root @ XKWB5705/] # rm-rvf/varOLD/hahah
Removed '/varOLD/hahah'
[Root @ XKWB5705/] # ls/varOLD/
What I want to do now is to clear all files in the/aniya/directory and delete the usr.tar.gz file package ]:
[Root @ XKWB5705/] # rsync -- delete-before-a-H-v -- progress -- stats/varOLD // aniya/
Building file list...
1 file to consider
Deleting usr.tar.gz
./
Number of files: 1
Number of files transferred: 0
Total file size: 0 bytes
Total transferred file size: 0 bytes
Literal data: 0 bytes
Matched data: 0 bytes
File list size: 28
File list generation time: 0.001 seconds
File list transfer time: 0.000 seconds
Total bytes sent: 50
Total bytes ed: 26
Sent 50 bytes encoded ed 26 bytes 152.00 bytes/sec
Total size is 0 speedup is 0.00
/Aniya/the directory is empty.
[Root @ XKWB5705/] # ls/aniya/
[Root @ XKWB5705/] # ls/aniya/
The above results show that:
If the SRC and DEST files are of different properties, an error is returned.
When SRC and DEST are both objects [f], this indicates clearing the object content rather than deleting the object.
When SRC and DEST are both directories [d], it means to delete all files in the directory and change it to an empty directory.
The most important thing is that the processing speed is quite fast. Processing Several GB of files is a matter of seconds.
The core content is: rsync actually uses the replacement principle
From: ANLJF's column