LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 02-28-2006, 12:07 PM   #1
Kropotkin
Member
 
Registered: Oct 2004
Location: /usr/home
Distribution: Fedora, Mint, FreeBSD, Android
Posts: 347

Rep: Reputation: 31
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

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

Rep: Reputation: 53
Code:
unzip /media/cdrecorder5/subdir/"*.zip"
?
 
Old 02-28-2006, 12:34 PM   #3
cconstantine
Member
 
Registered: Dec 2005
Distribution: RedHat, Ubuntu
Posts: 101

Rep: Reputation: 15
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
 
Old 02-28-2006, 12:45 PM   #4
unSpawn
Moderator
 
Registered: May 2001
Posts: 27,552
Blog Entries: 54

Rep: Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925Reputation: 2925
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
 
  


Reply


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 08:36 AM
bash: /bin/rm: Argument list too long? FiveFlat Linux - General 5 08-12-2004 12:29 AM
-bash: /bin/mv: Argument list too long balanagireddy Linux - General 2 07-28-2004 12:19 AM
Argument list too long trutnev Linux - General 3 04-22-2004 05:32 PM
/bin/rm: Argument list too long dragon49 Linux - Software 1 09-02-2003 01:27 PM


All times are GMT -5. The time now is 09:29 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration