1820483 Members
2282 Online
109624 Solutions
New Discussion юеВ

gzip

 
SOLVED
Go to solution
YOGI_3
Frequent Advisor

gzip

I am zipping files in one directory..
its giving following error....
[root@mbdelh01 ftp_cdr_completed]# gzip *
-bash: /bin/gzip: Argument list too long
[root@mbdelh01 ftp_cdr_completed]#
---------------------------------------------
How to gzip soo many files..
while moving *.gz its giving same error..

waiting for replies
thanks
There is never a wrong time to do the right things
6 REPLIES 6
Pete Randall
Outstanding Contributor
Solution

Re: gzip

You can use the find command to process them one at a time:

find /start_dir -type f -exec gzip {} \;

Same for moving. With that many files it may take a while though.


Pete

Pete
Rodney Hills
Honored Contributor

Re: gzip

Too many files error is because the shell parser expands all the filenames before it runs the command.

The standard method to get around this process is-
ls | xargs gzip

xargs breaks the arguments into managable chunks for gzip (or any command) to use.

HTH

-- Rod Hills
There be dragons...
James R. Ferguson
Acclaimed Contributor

Re: gzip

Hi:

Do something like:

cd your_directory
find . -type f > /tmp/mylist
while read FILE
do
gzip ... ${FILE} #...with whatever args...
done < /tmp/mylist

Regards!

...JRF...
Rodney Hills
Honored Contributor

Re: gzip

The method you are using will compress each file and keep it that way in the directory.

If you are compressing for purposes of transport, then a typical method is-

cd ftp_cdr_completed
tar cf . - | gzip -c >package.tar.gz

HTH

-- Rod Hills
There be dragons...
Geoff Wild
Honored Contributor

Re: gzip

I like the xargs method - but you could just tar them, then gzip the tarball...

Rgds...Geoff
Proverbs 3:5,6 Trust in the Lord with all your heart and lean not on your own understanding; in all your ways acknowledge him, and he will make all your paths straight.
Muthukumar_5
Honored Contributor

Re: gzip

Use with xargs or find -exec \+ method to do this easily.

ls | xargs gzip

find . -type f -exec gzip {} \+

You can also prefer to use tar all the files and gunzipping the tar.

find . -type f -exec gzip {} \; is having limitation problem too.

hth.
Easy to suggest when don't know about the problem!