| 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 {} \;
|
|
|
|