Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 02-28-2006, 11:07 AM   #1
Registered: Oct 2004
Location: /usr/home
Distribution: Linux Mint, FreeBSD, Android
Posts: 356

Rep: Reputation: 32
bash: /bin/ls: Argument list too long. Workaround?

Ahoy, all you command-line jocks out there. I have a CD of fonts which came only with a win installer. Examining the disk, it appears that the font files are all in five or so subdirectories, and each and every one of these files is zipped. In order to unzip them into subdirectories of ~/.font/ I ran the following command:

$ for i in `ls /media/cdrecorder5/subdir/*.zip`; do unzip $i; done
(where subdir is one of several font directories).

This worked fine until I got to a certain subdirectory which generated the following error message: bash: /bin/ls: Argument list too long/

According to $ ls | wc -l, in contains notabene 3307 (!) files. I tried narrowing the selection with | grep - ^[a-f] to no avail. I appear to be coming up against an internal limitation of bash. Any way of getting around this? Anything not to have to unpack those files one by one.


Last edited by Kropotkin; 02-28-2006 at 11:13 AM.
Old 02-28-2006, 11:17 AM   #2
Senior Member
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 55
unzip /media/cdrecorder5/subdir/"*.zip"
Old 02-28-2006, 11:34 AM   #3
Registered: Dec 2005
Distribution: RedHat, Ubuntu
Posts: 101

Rep: Reputation: 15
Originally Posted by Kropotkin
...order to unzip them into subdirectories of ~/.font/ I ran the following command:

$ for i in `ls /media/cdrecorder5/subdir/*.zip`; do unzip $i; done
how about...

$ find /media/cdrecorder5/subdir -f \*\.zip -exec unzip {} \;
clarification of backslashes: you don't want your shell interpretting the '*', '.' and ';' -- those need to go to find in the args... you could also single quote " -f '*.zip' " etc.

The empty curlies are substituted with the paritcular file found. So unzip will run separately ala

unzip /media/cdrecorder5/subdir/
unzip /media/cdrecorder5/subdir/

Dunno how unzip will behave, you may end up with zillions of files in your PWD...

I'm only chiming in with "how to use find" information...
Old 02-28-2006, 11:45 AM   #4
Registered: May 2001
Posts: 29,359
Blog Entries: 55

Rep: Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546Reputation: 3546
for item in *; do
...exactly the reason why you should prefer "while" over "for" loops unless you have specific requirements. The reason is the shell needs to expand into a list before it can act on the contents of that list, so: find /media/cdrecorder5/ -type f -iname \*.zip|while read f; do unzip "$f"; done
Now in your case you don't need a "for" loop either as you can get away with using xargs: find /media/cdrecorder5/ -type f -iname \*.zip|xargs unzip


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 On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
argument list to long for linux commands supersucker Linux - Newbie 1 05-10-2005 07:36 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
Argument list too long trutnev Linux - General 3 04-22-2004 04:32 PM
/bin/rm: Argument list too long dragon49 Linux - Software 1 09-02-2003 12:27 PM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 06:52 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration