Operating System - HP-UX
1832650 Members
2997 Online
110043 Solutions
New Discussion

How do I remove files w/in a directory with the size of 0?

 
SOLVED
Go to solution

How do I remove files w/in a directory with the size of 0?

Is there a bulk way to do this rather than individually?
7 REPLIES 7
Rick Garland
Honored Contributor

Re: How do I remove files w/in a directory with the size of 0?

One option would be to use the find command and looking at the file sizes.

Another would be to
ll | awk '{if (($5 == "0")) print $0}' | rm -f
Antoanetta Naghiu
Esteemed Contributor

Re: How do I remove files w/in a directory with the size of 0?

See the post about find command (yesterday one) with size option and combine it with exec rm.
Rick Garland
Honored Contributor

Re: How do I remove files w/in a directory with the size of 0?

Change the print $0 to print $9

Re: How do I remove files w/in a directory with the size of 0?

ll | awk '{if (($5 == "0")) print $0}' | rm -f

doesnt seem to be doing anything......they are still there......
Antoanetta Naghiu
Esteemed Contributor
Solution

Re: How do I remove files w/in a directory with the size of 0?

Try
# find / -size 0 -exec rm {}
Kofi ARTHIABAH
Honored Contributor

Re: How do I remove files w/in a directory with the size of 0?

have you tried:

find . -size 0 -exec rm -f {} \;

nothing wrong with me that a few lines of code cannot fix!

Re: How do I remove files w/in a directory with the size of 0?

It worked!!! Thanks!

I did:
find /opt/pkms/tmp -size 0 -exec rm {} ;