Unix questions - remove empty files

This is Interesting: Free IT Magazines  
Home > Archive > Unix questions > October 2004 > remove empty files





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author remove empty files
Gabriella

2004-10-04, 6:01 pm

I have a lot of empty files 0 ko. How I can remove these files ?

Thanks
Chris F.A. Johnson

2004-10-04, 6:01 pm

On 2004-10-04, Gabriella wrote:
> I have a lot of empty files 0 ko. How I can remove these files ?


I use zrm; it can be a function or a standalone script:

zrm() {
for f in "$@"
do
if [ ! -s "$f" ] ## if the file is empty
then
rm "$f"
fi
done
}

zrm *


--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
Chuck Dillon

2004-10-04, 6:01 pm

Gabriella wrote:
> I have a lot of empty files 0 ko. How I can remove these files ?
>
> Thanks


You can do:
find <dirs...> -size 0
to find them and use find with xargs to remove them...
find <dirs...> -size 0 | xargs rm

WARNING: Use find without xargs to verify you are getting the list you
want before applying the xargs+rm part. You can use 'xargs echo rm' to
further validate that you will be removing what you intend. The point
is be careful about how you do this kind of thing for obvious reasons.

-- ced

--
Chuck Dillon
Senior Software Engineer
NimbleGen Systems Inc.
Stephane CHAZELAS

2004-10-05, 3:01 am

2004-10-4, 14:56(-07), Gabriella:
> I have a lot of empty files 0 ko. How I can remove these files ?


With zsh:

rm ./*(D.L0)

Note the "." to only remove the regular files and "D" to also
remove dot files.

If you want to recursively descend into subdirectories:

rm ./**/*(D.L0)

--
Stephane
Stephane CHAZELAS

2004-10-05, 3:01 am

2004-10-4, 22:16(+00), Chris F.A. Johnson:
> On 2004-10-04, Gabriella wrote:
>
> I use zrm; it can be a function or a standalone script:
>
> zrm() {
> for f in "$@"


for f

is more portable

> do
> if [ ! -s "$f" ] ## if the file is empty
> then
> rm "$f"


rm -- "$f"

You may also want to check that the file is a regular file:

if [ -f "$f" ] && [ \! -L "$f" ] && [ ! -s "$f" ]

> fi
> done
> }
>
> zrm *


or zrm ./*


With zsh:

rm ./*(.L0)

--
Stephane
tosundaram@gmail.com

2004-10-08, 5:52 pm

Chuck Dillon <spam@nimblegen.com> wrote in message news:<cjsihl$3th$1@grandcanyon.binc.net>...
> Gabriella wrote:
>
> You can do:
> find <dirs...> -size 0
> to find them and use find with xargs to remove them...
> find <dirs...> -size 0 | xargs rm
>
> WARNING: Use find without xargs to verify you are getting the list you
> want before applying the xargs+rm part. You can use 'xargs echo rm' to
> further validate that you will be removing what you intend. The point
> is be careful about how you do this kind of thing for obvious reasons.
>
> -- ced



you use this:
find . -type f -size 0 -print -exec rm -f {} \;
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com