Operating System - HP-UX
1752796 Members
5827 Online
108789 Solutions
New Discussion юеВ

find command to delete zero files

 
rhansen
Frequent Advisor

find command to delete zero files

Hello,

I need to find zero bytes files and delete them (as part of the script).

I know i can use find . -type f -exec rm {}\; but the issue is it will delete all files under it and the directories below it. I do not want to go below the current directory.

Thanks ina advance.

3 REPLIES 3
Steven Schweda
Honored Contributor

Re: find command to delete zero files

Many "find" examples on this Forum.

http://forums.itrc.hp.com/service/forums/questionanswer.do?threadId=1276654

> [...] it will delete all files [...]

It sure will. "man find", look for "-size".
James R. Ferguson
Acclaimed Contributor

Re: find command to delete zero files

Hi:

# cd /path

# find . -type d ! -name . -prune -o -type f -size 0 -exec rm {} +

Verify that this gives you what you want by first substituting 'echo' for 'rm'.

Regards!

...JRF...
Torsten.
Acclaimed Contributor

Re: find command to delete zero files

But remember, some applications are creating lock files with a size of zero too. Deleting them may harm your system!

Hope this helps!
Regards
Torsten.

__________________________________________________
There are only 10 types of people in the world -
those who understand binary, and those who don't.

__________________________________________________
No support by private messages. Please ask the forum!

If you feel this was helpful please click the KUDOS! thumb below!