Find bulk Delete empty files and empty folder scripts in Linux

Source: Internet
Author: User
Tags svn

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).

Query out all the empty folders

The code is as follows Copy Code

Find-type D-empty

deleting files

List the files that are searched

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


Bulk delete files that you have searched for

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


Prompt before deleting

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.-name There are also spaces
3.exec is a subsequent command, {} content represents the previously found file

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.