Find bulk Delete empty files and empty folders in Linux

Source: Internet
Author: User
Tags svn

How to bulk delete 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

You can also delete a file of the 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 files of 1k size. (but be careful not to use-size 1k, this gets to occupy space 1k, not file size 1k).

Query out all empty folders

The code is as follows Copy Code

Find-type D-empty

deleting files

List the files you have searched for

The code is as follows Copy Code
Find. -name "Shuaige.txt"-exec ls {};


Delete a searched file in bulk

The code is as follows Copy Code
Find. -name "Shuaige.txt"-exec rm-f {};


Prompt before deletion

The code is as follows Copy Code

Find. -name "Shuaige.txt"-ok rm-rf {};


Delete the files under all the test folders under the current directory

The code is as follows Copy Code

Find. -name "Test"-type d-exec rm-rf {};

Delete all the. svn files under the folder

The code is as follows Copy Code

Find. -name '. SVN '-exec rm-rf {};

Note:

1.{} and there is a space between
2.find. There are also spaces between-name
3.exec is a follow-up command, and the contents of {} represent the files found earlier

Find bulk Delete empty files and empty folders in Linux

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.