LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   bash: /bin/ls: Argument list too long. Workaround? (https://www.linuxquestions.org/questions/linux-general-1/bash-bin-ls-argument-list-too-long-workaround-420327/)

Kropotkin 02-28-2006 11:07 AM

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:

Code:

$ 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. :(

TIA

nx5000 02-28-2006 11:17 AM

Code:

unzip /media/cdrecorder5/subdir/"*.zip"
?

cconstantine 02-28-2006 11:34 AM

Quote:

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

Code:

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

how about...

Code:

$ 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/foo.zip
unzip /media/cdrecorder5/subdir/bar.zip
etc

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...
-c

unSpawn 02-28-2006 11:45 AM

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


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