remove empty files
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix questions > remove empty files




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    remove empty files  
Gabriella


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-04-04 11:01 PM

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

Thanks





[ Post a follow-up to this message ]



    Re: remove empty files  
Chris F.A. Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-04-04 11: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





[ Post a follow-up to this message ]



    Re: remove empty files  
Chuck Dillon


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-04-04 11: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.





[ Post a follow-up to this message ]



    Re: remove empty files  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-05-04 08: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





[ Post a follow-up to this message ]



    Re: remove empty files  
Stephane CHAZELAS


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-05-04 08: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





[ Post a follow-up to this message ]



    Re: remove empty files  
tosundaram@gmail.com


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
10-08-04 10: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 {} \;





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 12:23 PM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register