LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-06-2006, 08:57 AM   #1
konathamsrinu
LQ Newbie
 
Registered: Jul 2006
Posts: 5

Rep: Reputation: 0
Zip gives error "-bash: /usr/bin/zip: Argument list too long"


Hi All,
my zip program gives me the error
"-bash: /usr/bin/zip: Argument list too long"
When there are more than 3100 files in a directory.
working fine when the files are <3100,
I know there is no limit for the files in the zip,
Am not sure why i am getting this error.File name are having aroung 46 char long.
Is there a limit to files or file names for zip program?
command executing:
zip -r -q -j abc.zip *.pdf

Any assistance would be highly appreciated
Thanks in Advance
Srinivas
 
Old 07-06-2006, 10:03 AM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
The restriction is the lenght of the parameter list in the shell; not specific to any program. I'm sure an 'ls *.pdf' gives the same result.

The shell attempts to find all the *.pdf files and pass them as arguments to ls. It's the length of the filenames and the number that exceeds the arg limit, not just the 3100 files.

The code below uses find which does not do the expansion, but checks the files one at a time. Passing the results to zip.
Code:
find . -name '*.pdf' -print | zip pdfFiles.zip -@
 
Old 07-06-2006, 10:05 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

Zip is not the problem, bash is.

Command line expansion comes before the zip command, so *.pdf is expanded first and then zip is given the files. The expansion of *.pdf generates the error.

To my knowledge the argument list can only be X files long, X depending on platform, hardware, OS etc.

You could use find and pipe to zip.

Hope this helps.
 
Old 07-06-2006, 10:08 AM   #4
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
There is a limit in bash on how much memory the command line arguments can occupy.
You might try using find and xargs instead.

find ./ -iname "*.pdf" | xargs -l 1000 zip -r -q -j abc.zip
The xargs program will take the stdout from the "|" pipe and use them for the command line arguments. The -l "el" option limits the number of lines expanded at a time.

You might consider using tar instead, unless you are zipping the files for windows users.

See "man find", "man xargs" and "man tar" for more details.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
bash: /bin/ls: Argument list too long. Workaround? Kropotkin Linux - General 3 02-28-2006 11:45 AM
bash: /bin/rm: Argument list too long? FiveFlat Linux - General 5 08-11-2004 11:29 PM
-bash: /bin/mv: Argument list too long balanagireddy Linux - General 2 07-27-2004 11:19 PM
Synaptic error: "sub-process /usr/bin/dpkg returned an error code (2)" firefly2442 Linux - Software 3 02-04-2004 06:41 PM
/bin/rm: Argument list too long dragon49 Linux - Software 1 09-02-2003 12:27 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:15 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration