Introduction to commands for deleting batch and empty files in linux

Source: Internet
Author: User
This chapter provides a detailed explanation of how to batch delete files and empty files in linux"

Delete a file or directory command rm (remove) in linux)

Function description: delete a file or directory.

Syntax: rm [-dfirv] [-- help] [-- version] [file or directory...]
Note: execute the rm command to delete a file or directory. if you want to delete a directory, you must add the "-r" parameter. Otherwise, only the file will be deleted by default.
Parameters:
-D or -- directory directly delete the hard connection data of the directory to be deleted to 0 and delete the directory.
-F or -- force forcibly deletes a file or directory.
-I or -- interactive ask the user before deleting an existing file or directory.
-R,-R, or -- recursive processing: All files and subdirectories under the specified directory are processed together.
-V or -- verbose displays the command execution process.
-- Help online help.


How to batch delete empty files (files with a size equal to 0) in Linux

The code is as follows:

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

You can also delete a file of the specified size by modifying the corresponding-size parameter, for example:

The code is as follows:

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

Delete an object of 1 kB. (But do not use-size 1 k. the occupied space is 1 k, not the file size 1 k ).

If you only need to delete folders or name connections, you can change the-type parameter accordingly. for details, see man find.

Delete files N days ago

LINUX batch delete files by time (delete files N days ago)


The code is as follows:

Find/opt/Oracle/admin/CCXE/bdump/-mtime + 10-name "*. *"-exec rm-Rf {};

/Opt/Oracle/admin/CCXE/bdump/: any directory to be cleaned

-Mtime: Standard statement writing
+ 10: search for files 10 days ago. here, the number represents the number of days, and the number plus 30 represents the number of files 30 days ago.

"*. *": The data type you want to search for. "*. jpg" indicates all files with the jpg extension and "*" indicates all files.
-Exec: fixed syntax

Rm-rf: force delete files, including directories
{};: Fixed writing method, a pair of braces + spaces +/+;

Permanently delete an object

In some cases, we need to completely delete some files, which can be implemented using the shred command. shred is part of coreutils, so this command is basically used in Linux.

Shred:

The code is as follows:

$ Shred-u file

Shred will overwrite the node and data block where the file is located with some random content, and delete the file (-u parameter ).

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

The code is as follows:

$ Shred-u-z file

In addition, shred can also clear the entire partition or disk. for example, to completely clear the content of the/dev/sdb1 partition, you can do this:

$ Shred/dev/sdb1 (do not add the-u parameter)

Detailed shred parameters:

-F, -- force: change the permission to allow write (if necessary)

-N, -- iterations = N rewrite N times. The default value is 3 times.

-- Random-source = FILE: reads data from a specified FILE

-S, -- size = N to smash the file to a fixed size (suffixes such as K, M, and C can be used)

-U, -- remove rewrite and truncate and remove the file

-V, -- verbose shows the progress

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

-Help: Display help

-Version: displays version information.

Related Article

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.