gzip

Hi,

I want to gzip files in loop.

for i in `ls *.xml`;
do
gzip $i;
done

But i am gettin error like "/usr/bin/ls: Arg list too long"

Also please tell me how to do it with while loop and also using find and then exec.

try:

find . -name "*.xml" -exec gzip {} \;

Thanks a lot!!

In for loop i want to aviod this "argument list too long error".

How should i make it fetch 100 files at a time or may be one by one.

find . -name *.xml -exec gzip {} \;
It again gives the same error.
:slight_smile:

for each in $(find . -name "*.xml")
do
.....
done

Am not convinced!!!! :rolleyes:

Try it with xargs:

find . -name "*.xml" |xargs gzip

Regards

Yes Dennis ur rite, 'find' is working.
But still one problem is there, as there are already some zipped files in it.
So i having a continous prompt of overwrite.
"do you wish to overwrite (y or n)?"

How to overcome it and also how to run this loop in background.

For issue of prompting to overwrite,

Use gzip -f option

For running it in background, use & at the end..

ie,

find . -name "*.xml" -exec gzip -f {} \; &

or as Franklin suggested,

find . -name "*.xml" | xargs gzip -f &

Thanxx a lot to both of you Franclin and Dennis!!!

It worked......:slight_smile: