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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
06-30-2005, 08:30 PM
|
#1
|
LQ Newbie
Registered: Jun 2005
Posts: 6
Rep:
|
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
|
|
|
06-30-2005, 08:33 PM
|
#2
|
Member
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944
Rep:
|
How about "unzip *.zip"?
|
|
|
06-30-2005, 08:37 PM
|
#3
|
LQ Newbie
Registered: Jun 2005
Posts: 6
Original Poster
Rep:
|
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
|
|
|
06-30-2005, 08:42 PM
|
#4
|
Member
Registered: Jun 2005
Posts: 96
Rep:
|
try:
Code:
for i in `ls -1 | grep .zip$`; do unzip $i; done
hope this helps
|
|
|
06-30-2005, 08:44 PM
|
#5
|
Member
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944
Rep:
|
How about this then:
Code:
for i in `ls`; do unzip $i; done
|
|
|
06-30-2005, 08:45 PM
|
#6
|
Member
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944
Rep:
|
Beat me to it and I'm glad you did. I was trying to unzip everything. Do you need the -l though?
|
|
|
06-30-2005, 08:48 PM
|
#7
|
LQ Newbie
Registered: Jun 2005
Posts: 6
Original Poster
Rep:
|
mhallbiai, jrdioko,
Both your solutions worked fine. Thanks for your help and quick responses.
Much appreciated.
-T
|
|
|
06-30-2005, 09:01 PM
|
#8
|
Member
Registered: Jun 2005
Posts: 96
Rep:
|
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
|
|
|
06-30-2005, 09:29 PM
|
#9
|
Member
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944
Rep:
|
Thanks for the explanation, it's about time I learn how to use those for loops.
|
|
|
08-08-2005, 02:05 PM
|
#10
|
Member
Registered: Oct 2003
Location: MN
Distribution: CentOS, Fedora
Posts: 182
Rep:
|
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!
|
|
|
08-08-2005, 02:11 PM
|
#11
|
Member
Registered: Oct 2002
Distribution: Debian 6.0.2 (squeeze)
Posts: 944
Rep:
|
What does the following return:
|
|
|
08-08-2005, 02:18 PM
|
#12
|
Senior Member
Registered: Apr 2004
Location: Baton Rouge, Louisiana, USA
Distribution: Debian Stable
Posts: 2,546
|
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.
|
|
|
08-08-2005, 02:25 PM
|
#13
|
LQ Guru
Registered: Nov 2004
Location: San Jose, CA
Distribution: Debian, Arch
Posts: 8,507
Rep: 
|
Not to be difficult, but why not just:
Rather than going through grep?
Phaethar, make sure you are using backticks (same key as the tilde: ~), not single quotes or anything.
|
|
|
08-29-2014, 11:34 AM
|
#14
|
LQ Newbie
Registered: Aug 2014
Posts: 1
Rep: 
|
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 
|
|
|
08-29-2014, 11:46 AM
|
#15
|
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
|
Quote:
Originally Posted by mhallbiai
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
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
|
|
|
All times are GMT -5. The time now is 11:19 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|