LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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: 16
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: 16
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 Stable
Posts: 2,546
Blog Entries: 8

Rep: Reputation: 465Reputation: 465Reputation: 465Reputation: 465Reputation: 465
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
LQ Guru
 
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507

Rep: Reputation: 128Reputation: 128
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.
 
Old 08-29-2014, 11:34 AM   #14
rdeep
LQ Newbie
 
Registered: Aug 2014
Posts: 1

Rep: Reputation: Disabled
try this simple command :

unzip "*.zip" -d <directory_path>;

PS: this would unzip all the .zip files into the mentioned directory.
Note the difference in placing the commas
 
Old 08-29-2014, 11:46 AM   #15
frieza
Senior Member
 
Registered: Feb 2002
Location: harvard, il
Distribution: Ubuntu 11.4,DD-WRT micro plus ssh,lfs-6.6,Fedora 15,Fedora 16
Posts: 3,233

Rep: Reputation: 406Reputation: 406Reputation: 406Reputation: 406Reputation: 406
Quote:
Originally Posted by mhallbiai View Post
try:
Code:
for i in `ls -1 | grep .zip$`; do unzip $i; done
hope this helps
a bit excessive, but works

Quote:
Originally Posted by jrdioko View Post
How about this then:

Code:
for i in `ls`; do unzip $i; done
works if only zip files in directory

though technically `ls` is depricated in favor of $(ls)

a better way would be
Code:
for i in $(ls *.zip)
do
unzip $i
done
but an even more efficient way would be simply
Code:
for zipfile in *.zip
do
unzip $zipfile
done
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

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

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration