Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to delete many 0 byte files in linux?

I've a directory with many number of 0 byte files in it. I can't even see the files when I use the ls command. I'm using a small script to delete these files but sometimes that does not even delete these files. Here is the script:

i=100 while [ $i -le 999 ];do     rm -f file${i}*;     let i++; done 

Is there any other way to do this more quickly?

like image 449
small_ticket Avatar asked Jul 01 '10 11:07

small_ticket


People also ask

How do I remove zero size files in Linux?

The first part,-type d -empty -print -delete, will delete all the empty directories, and the second part, -type f -empty -print -delete, will delete all the empty files.

How do I get rid of 0-byte files?

Before entering a command, right-click the taskbar and select Task Manager. Then right-click explorer.exe (Windows Explorer) in the Processes tab and select End task. Enter cd byte file path in the Command Prompt and press Enter. Replace '0-byte file path' with the actual folder path of the file.


1 Answers

Use find combined with xargs.

find . -name 'file*' -size 0 -print0 | xargs -0 rm 

You avoid to start rm for every file.

like image 153
Didier Trosset Avatar answered Dec 08 '22 10:12

Didier Trosset