Linux delete files and a large number of file deletion methods

Source: Internet
Author: User
Tags mkdir sprintf rsync


Delete folder: RM-RF [Folderdir]

Copy folder: CP-RF [Srcdir] [Dstdir]


Linux Delete files, the folder is mainly used in the command is RM, the following will be a simple introduction to the Linux RM command.

Grammar:

RM [Options] DirName

The options in this command are commonly used in the following ways: Www.111cn.net

-I delete the query confirmation before

-F Even if the deleted file's properties are read-only, and deleted directly, without confirmation, the default is to be confirmed one by one.

-R Deletes the directory and all of the following files individually

Example:

Rm-i *.php Delete all files that are suffix PHP; ask for confirmation before deleting

Rm-r Phpernote deletes all files in the Phpernote directory and subdirectories, and when the file is read-only, prompts to delete

Rm-rf/www.111cn.net/access will delete the/www.111cn.net/access directory and all the files and folders under it and delete without any deletion confirmation
Tips

Attention:

(1) There is no Recycle Bin in Linux, so when using the RM command, remember that the file or directory is deleted and cannot be recovered.

(2) If the prompt does not have permission to run the command, you can use sudo to elevate the user's permissions and then execute the command

How do I delete a large file?

Google came out with test data, but the test environment was not written.
Personal feeling has a lot to do with file system formats.

Today I took a moment to test:
The test machine configuration is lower, it is the desktop that bought in n years ago.
SATA Hard Drives
Intel (R) Pentium (r) D CPU 3.20GHz
4G of memory.
EXT4 File System:
/dev/mapper/volgroup-lv_home on/home type EXT4 (rw,noatime)
Linux www 2.6.32-220.7.1.el6.i686 #1 SMP Tue Mar 6 21:21:22 GMT i686 i686 i386 gnu/linux
CentOS Release 6.2 (Final)
Rsync version 3.0.6 protocol version 30

Create a 16/256/directory structure that holds 250 files in the deepest directory, 300 bytes per file.
mkdir.php

The code is as follows Copy Code

/**
16 * 256 * 250
*/

For ($i =0 $i <=0xF; $i + +) {
For ($j =0 $j <=0xF; $j + +) {
For ($m =0 $m <=0xF; $m + +) {

$dirname = sprintf ("test/%x/%x%x", $i, $j, $m);
Create a table of contents
mkdir ($dirname, 0755, TRUE);

For ($k =-0 $k <250; $k + +) {
$filename = sprintf ("%s/%d.html", $dirname, $k);
File_put_contents ($filename, Str_repeat ("111", 100));
}
}
}
}

Find traverse once takes 35 seconds:
[modify@www Test] $time find./-type F |wc-l
1024000

Real 0m35.679s
User 0m1.559s
SYS 0m9.946s

The rsync of Baidu to the Remove method first creates an empty directory empty and then synchronizes with rsync
[Root@www modify]# time rsync--delete-before-d empty/test/

Real 1m13.964s
User 0m1.933s
SYS 0m35.384s

Google to the rsync removal method
[modify@www ~] $time rsync-a--delete empty/test/

Real 1m8.685s
User 0m1.919s
SYS 0m35.113s

Find F Delete:
[Root@www modify]# time Find test/-type f-delete

Real 1m11.396s
User 0m1.484s
SYS 0m34.422s

Find Xargs is definitely slower than find delete because there are more pipes. On the accident.

Find Xargs 16 process, a bit of an opportunistic feeling, is actually running 16 RM–RF to delete the first level subdirectory:
[Root@www modify]# CD test/
[Root@www test]# time Find./-maxdepth 1 | Xargs-n 1-p RM-RF
Rm:cannot Remove directory: '. '

Real 1m3.160s
User 0m1.022s
SYS 0m41.364s

Rm–rf
[Root@www modify]# time RM test/-RF

Real 1m20.334s
User 0m1.074s
SYS 0m32.179s
Conclusion:

It seems that the various ways of deletion are very close.

PS: Later found that each repeat test, the data will have a certain float. Should take the average number of times ...
PS2: Ask for XFS test data. Ext3 just forget it. The article on the net, may refer to is the ext3.

Finally said a few eclectic scenarios:
MV is the fastest, less than 0.1 seconds, and then can be put to the background to slowly delete (Nice-n 20). The
Mkfs is also a good choice under certain conditions.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.