Linux Bulk Delete file and empty file Delete command

Source: Internet
Author: User

Linux Delete file or directory command RM (remove)

Feature Description: Deletes a file or directory.

Syntax: RM [-dfirv][--help][--version][file or directory ...]
Supplemental Note: Perform RM directives to delete files or directories, and if you want to delete the directory you must add the parameter "-r", otherwise the preset will only delete the file.
Parameters
-D or--directory deletes the hard connection data of the directory to be deleted directly to 0, deleting the directory.
-F or--force forcibly deletes a file or directory.
-I or--interactive ask the user before deleting the existing file or directory.
-R or-R or--recursive recursively, all files and subdirectories under the specified directory are processed together.
The-V or--verbose displays the instruction execution process.
--help online Help.


method of bulk deleting empty files (Files of size equal to 0) under Linux

The code is as follows Copy Code

Find. -name "*"-type f-size 0c | Xargs-n 1 rm-f

This also allows you to delete a file of a specified size, as long as you modify the corresponding-size parameter, for example:

The code is as follows Copy Code

Find. -name "*"-type f-size 1024c | Xargs-n 1 rm-f

is to delete a 1k size file. (but be careful not to use the-size 1k, this gets the Occupy space 1k, not the file size 1k).

If you delete the folder or the name of the connection, you can change the corresponding-type parameters, see the details of the man found

Delete N days ago File

Linux Bulk Delete files in time (delete n days ago file)

The code is as follows Copy Code
find/opt/oracle/admin/ccxe/bdump/-mtime +10-name "*.*"-exec rm-rf {};


/opt/oracle/admin/ccxe/bdump/: Any directory that you want to clean

-mtime: The standard sentence formulation
+10: Find 10 days before the file, where the number of days to represent, +30 to find 30 days before the file

"*.*": the type of data you want to find, "*.jpg" means to find all files with the extension jpg, "*" to find all files
-exec: Fixed wording

RM-RF: Force delete files, including directories
{} ; : fixed wording, a pair of curly braces + space +/+;

Delete Files completely

Sometimes we have to completely delete some files, you can use the Shred command to achieve, shred is a part of the coreutils, so the basic Linux will have this command.

Shred the method of deleting a file completely:

The code is as follows Copy Code

$ shred-u File

Shred uses random content to overwrite the nodes and blocks of the file, and deletes the file (-u parameter).

If you want to erase a bit more thoroughly you can add the-z parameter, which means you fill it with random data and then fill it with 0.

The code is as follows Copy Code

$ shred-u-Z File

In addition shred can also clear the entire partition or disk, such as want to completely clear the contents of/DEV/SDB1 partition can be this way:

$ SHRED/DEV/SDB1 (note do not add-u parameter)

Shred's detailed parameters:

-F,--force Change permissions allow write (if necessary)

-N,--iterations=n rewrite n times, defaults to 3 times

--random-source=file reads data from a specified file

-S,--size=n the file to a fixed size (you can use suffixes such as K, M, C, etc.)

-U, truncate and remove files after--remove rewrite

-V,--verbose show progress

-Z,--zero-add overwrite data with 0

–HELP Display Help

–version Display version Information

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.