LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices

Reply
 
Search this Thread
Old 06-30-2005, 08:30 PM   #1
tes15
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Rep: Reputation: 0
unzip all .zip files in a directory


Hi,

I was wondering if anyone is able to help with my query. I am trying to unzip every .zip file in a certain directory. I am using the # unzip command and at present I am unzipping each file singularly.

I have searched the man pages on 'unzip' but cannot find any directions/options outlining if it is possible to globally unzip all .zip files in a directory in one command.

If anyone has any suggestions, comments it would be greatly appreciated.

Thanks,

-T
 
Old 06-30-2005, 08:33 PM   #2
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
How about "unzip *.zip"?
 
Old 06-30-2005, 08:37 PM   #3
tes15
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Original Poster
Rep: Reputation: 0
Hi jrdioko.

Initially, I tried the unzip command with that syntax and received the following error for each respective zip file: "caution: filename not matched: <file>.zip"

It does seem strange that global pattern matching does not work with the unzip command (or perhaps it does and I don't know about it?).

Thanks for the suggestion.

-T
 
Old 06-30-2005, 08:42 PM   #4
mhallbiai
Member
 
Registered: Jun 2005
Posts: 96

Rep: Reputation: 15
try:
Code:
for i in `ls -1 | grep .zip$`; do unzip $i; done
hope this helps
 
Old 06-30-2005, 08:44 PM   #5
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
How about this then:

Code:
for i in `ls`; do unzip $i; done
 
Old 06-30-2005, 08:45 PM   #6
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Beat me to it and I'm glad you did. I was trying to unzip everything. Do you need the -l though?
 
Old 06-30-2005, 08:48 PM   #7
tes15
LQ Newbie
 
Registered: Jun 2005
Posts: 6

Original Poster
Rep: Reputation: 0
mhallbiai, jrdioko,

Both your solutions worked fine. Thanks for your help and quick responses.

Much appreciated.

-T
 
Old 06-30-2005, 09:01 PM   #8
mhallbiai
Member
 
Registered: Jun 2005
Posts: 96

Rep: Reputation: 15
jrdioko,

the -1 (number one) would ensure that it only fed one filename at a time without any permissions in case of an alias to ls that did not feed just the filenames to unzip.

i also added the grep to ensure that only files ending in .zip would be read

your solution works under ideal conditions which rarely exist for me

tes15, glad to help
 
Old 06-30-2005, 09:29 PM   #9
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
Thanks for the explanation, it's about time I learn how to use those for loops.
 
Old 08-08-2005, 02:05 PM   #10
Phaethar
Member
 
Registered: Oct 2003
Location: MN
Distribution: CentOS, Fedora
Posts: 182

Rep: Reputation: 30
Hey guys,

I know this topic is a bit old, but I'm running into the same issues, but I can't get the solution here to work either.

First, I'm getting exactly the same thing trying 'unzip *.zip'. I have about 30 files, and I get the "caution: filename not matched: <filename>.zip" error message.

So, I being that there are other files that are not .zip, I tried mhallbiai's solution and ran this:

for i in `ls -1 | grep .zip$`; do unzip $i; done

which, in turn, gave me this:

unzip: cannot find or open ls, ls.zip or ls.ZIP

I tried doing them one at a time and putting it in a simple shell script, but no luck.

So, I figure I'm missing something here, and hoping for an easy explanation.

BTW, this system does not have a GUI installed, so this has to be done through the CLI. Really hoping I don't have to sit there and manually unzip almost 30 zip files that are all almost 700MB!

Thanks!
 
Old 08-08-2005, 02:11 PM   #11
jrdioko
Member
 
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944

Rep: Reputation: 30
What does the following return:

Code:
ls -1 | grep .zip$
 
Old 08-08-2005, 02:18 PM   #12
IsaacKuo
Senior Member
 
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian 4.0 Etch
Posts: 1,349

Rep: Reputation: 49
Make sure the quotes you're typing in are "backquotes" (on my keyboard, it's on the upper left corner underneath "Esc"). Backquotes tell the shell to execute the contents, rather than just quoting the contents.

I personally find it an outrageously ugly syntax "feature".

Also, I'd put double quotes around $i, like so:

unzip "$i"

That's needed to work if some of the zip files have spaces.
 
Old 08-08-2005, 02:25 PM   #13
Matir
Moderator
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Ubuntu
Posts: 8,507

Rep: Reputation: 116Reputation: 116
Not to be difficult, but why not just:
Code:
ls -1 *.zip
Rather than going through grep?

Phaethar, make sure you are using backticks (same key as the tilde: ~), not single quotes or anything.
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unzip multiple zip files, each to separate folder smart_sagittari Linux - Newbie 3 03-21-2012 08:41 AM
unzip .zip >4gb dkw Linux - General 1 07-07-2005 07:27 PM
How to Unzip 2 Zip files through one single command sumitarun Linux - Newbie 2 03-23-2005 08:00 AM
Zip and Unzip concoran Linux - General 4 08-02-2002 07:12 PM
how do i unzip a .zip? lax2sman Linux - General 2 02-11-2002 05:17 PM


All times are GMT -5. The time now is 08:56 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