17

Thanks,in advance I want to remove all the zero size files in specified directory,can u tell me the command how to do it on Ubuntu OS.

Thanks' Mukthyar

Hema Latha
  • 185
  • 1
  • 2
  • 6
  • 4
    There's a duplicate question [How to remove zero byte files](http://stackoverflow.com/questions/15859712/how-to-remove-zero-byte-files) with a more extensive answer. I remain to be convinced that shell programming questions should be closed as off-topic; shell programming is programming and hence on-topic at SO. – Jonathan Leffler Apr 07 '13 at 15:22
  • See http://stackoverflow.com/questions/3157343/ and http://stackoverflow.com/questions/5475905 as well – John_West Jul 08 '16 at 10:26

2 Answers2

26

find . -size 0c -delete removes all such files in the current folder.

soulmerge
  • 73,842
  • 19
  • 118
  • 155
  • Thanks,in advance If i want to remove all the zero size files,folder in specified directory,then how to do it... – Hema Latha Mar 30 '12 at 10:35
  • I'm not sure I understood you right, but the dot in the command is the current directory. If you want to delete the zero-byte files in folder `/foo/bar`, you issue `find /foo/bar -size 0c -delete`. – soulmerge Mar 30 '12 at 15:35
  • I like to use -type f to explicitly get just the files if the directory has deeper folders. – Urchin Jul 16 '14 at 19:54
5
cd DIRECTORY
find . -size 0

If you want to run a command on the files found (e.g. delete)

find . -size 0 -exec rm {} \;
fragmentedreality
  • 1,287
  • 9
  • 31