How to use Linux to use rsync command to delete small files in batches

  

Linux system will generate many useless small files after a long time of use. If you need to waste a lot of time to delete one by one, then there is a good way to quickly delete these small files. What? This needs to be handled using the rsync command.

1. rsync installed, some of the default command

Ubuntu system installed: sudo apt-get install rsync

Fedora system: sudo yum install rsync < Br>

2. rsync provides some parameters related to deletion

rsync --help |  Grep delete

--del an alias for --delete-during

--delete delete extraneous files from destination dirs

--delete-before receiver deletes before transfer, Not during

--delete-during receiver deletes during transfer (default)

--delete-delay find deletions during, delete after

--delete-after receiver deletes After transfer, not during

--delete-excluded also delete excluded files from destination dirs

--ignore-errors delete even if there are I/O errors

- -max-delete=NUM don‘t delete more than NUM files

where --delete-before the recipient deletes before the transfer

3. Example

Empty Directory or file, as follows:

First, create an empty directory

mkdir /data/blank

Second, use rsync to delete the target directory

rsync --delete-before -d -a -H -v --progress --stats /data/blank//var/edatacache/

or

rsync --delete-before -d /data/blank//var/edatacache/

This way the /var/edatacache directory is quickly emptied.

Option Description:

–delete-before Receiver deletes before transfer

–progress shows transfer process during transfer

- a Archive mode, which means that files are recursively transferred, and all file attributes are kept

-H files that are hard-wired

-v detailed output mode

–stats The transfer status of some files

-d transfer directories without recursing

Third, it can also be used to delete large files

If we have a few under /root/Ten G or even hundreds of G file data, now we want to delete it

1), create an empty file

touch /root/empty

2), use rsync Empty /root/data file

rsync --delete-before -d --progess --stats /root/empty /root/data

Note:

When SRC Will be reported when the nature of the DEST file is inconsistent

When the properties of SRC and DEST are both file [f], it means to clear the contents of the file instead of deleting it.

When the properties of SRC and DEST are both directory [d], it means to delete all the files in the directory, making it empty.

The above is the batch deletion of Linux using the rsync command. The method of small files is introduced. After using the rsync command, even hundreds of thousands of small files can be deleted quickly, saving you valuable time.

Copyright © Windows knowledge All Rights Reserved