Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 07-06-2006, 08:57 AM   #1
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 *.pdf

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

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.
find . -name '*.pdf' -print | zip -@
Old 07-06-2006, 10:05 AM   #3
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399Reputation: 2399

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
LQ Guru
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678Reputation: 678
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
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.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:25 PM.

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