Linux delete file with size 0 [duplicate]

2019-01-20 23:40发布

This question already has an answer here:

How do I delete a certain file in linux if its size is 0. I want to execute this in an crontab without any extra script.

l filename.file | grep 5th-tab | not eq 0 | rm

Something like this?

8条回答
何必那么认真
2楼-- · 2019-01-21 00:13

you would want to use find:

 find . -size 0 -delete
查看更多
三岁会撩人
3楼-- · 2019-01-21 00:14

To search and delete empty files in the current directory and subdirectories:

find . -type f -empty -delete

-type f is necessary because also directories are marked to be of size zero.


The dot . (current directory) is the starting search directory. If you have GNU find (e.g. not Mac OS), you can omit it in this case:

find -type f -empty -delete

From GNU find documentation:

If no files to search are specified, the current directory (.) is used.

查看更多
登录 后发表回答