Using RM-RF * When we want to delete tens of thousands of or hundreds of thousands of or even millions of of files in a Linux system is not very useful because it takes a long time to wait. In this case, we can use the Linux system command rsync to skillfully handle. Rsync actually uses the principle of substitution, processing hundreds of thousands of files is also a second deletion.
1. rsync installation, some systems have this command installed by default
Ubuntu System:
The code is as follows:
sudo apt-get install rsync
Fedora System:
The code is as follows:
sudo yum install rsync
Other source can be installed, to the following Web site download
http://rsync.samba.org
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 the--delete-before receiver deletes before transmission
3. Example
Empty the directory or file as follows:
1, first set up an empty directory
The code is as follows:
Mkdir/data/blank
2, use rsync to delete the target directory
The code is as follows:
rsync--delete-before-d-a-h-v--progress--stats/data/blank//var/edatacache/
Or
The code is as follows:
rsync--delete-before-d/data/blank//var/edatacache/
So the/var/edatacache directory is quickly emptied.
Option Description:
–delete-before recipient to delete before transmission
–progress Displays the transfer process during transmission
-a archive mode, which represents the transfer of files recursively and maintains all file attributes
-H Keep Hard connected files
-V Verbose output mode
–stats gives the transfer status of some files
-D Transfer Directories without recursing
Delete Folder
This method is useful if a large number of small files are concentrated in several directories.
The code is as follows:
Rm-f/var/log/httpd/access.log
Will force deletion of/var/log/httpd/access.log this file
-R is recursive down, no matter how many levels of directory, delete
-F is simply forced to delete, without any hint of the meaning
-I for interactive deletion.
Tip: Be careful with RM commands. Because once the file is deleted, it cannot be restored. Prevents this from happening, you can use the I option to confirm the files that you want to delete individually. If the user enters Y, the file is deleted. If you enter anything else, the file is not deleted.
Use this RM-RF to delete files with extreme caution, Linux does not have a recycle Bin.
Rm-r Directory Name:
Delete all files in subdirectories and subdirectories
The code is as follows:
[Root@localhost test]# Ls-l
Total 24drwxr-xr-x 7 root root 4096 10-25 18:07 SCF
Drwxr-xr-x 2 root root 4096 10-26 14:51 test1
Drwxr-xr-x 3 root root 4096 10-25 17:44 test2
DRWXRWXRWX 2 root root 4096 10-25 17:46 test3
Drwxr-xr-x 2 root root 4096 10-25 17:56 test4
Drwxr-xr-x 3 root root 4096 10-25 17:56 test5
The code is as follows:
[Root@localhost test]# rm-r test1
RM: Do you want to enter the directory "Test1"? Y
RM: Do you want to delete the generic file "Test1/log3.log"? Y
RM: Do you want to delete the directory "Test1"? Y
The code is as follows:
[Root@localhost test]# Ls-l
Total 20drwxr-xr-x 7 root root 4096 10-25 18:07 SCF
Drwxr-xr-x 3 root root 4096 10-25 17:44 test2
DRWXRWXRWX 2 root root 4096 10-25 17:46 test3
Drwxr-xr-x 2 root root 4096 10-25 17:56 test4
Drwxr-xr-x 3 root root 4096 10-25 17:56 test5
[Root@localhost test]#
RM-RF Directory Name:
Delete all files in the directory and subdirectory, and do not use one by one confirmation
The code is as follows:
[Root@localhost test]# RM-RF test2
[Root@localhost test]# Ls-l
Total 16drwxr-xr-x 7 root root 4096 10-25 18:07 SCF
DRWXRWXRWX 2 root root 4096 10-25 17:46 test3
Drwxr-xr-x 2 root root 4096 10-25 17:56 test4
Drwxr-xr-x 3 root root 4096 10-25 17:56 test5
[Root@localhost test]#