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 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 |
Code:
unzip /media/cdrecorder5/subdir/"*.zip" |
Quote:
Code:
$ find /media/cdrecorder5/subdir -f \*\.zip -exec unzip {} \; 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 |
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. |