tags:

views:

20

answers:

2

Hello,

I have a folder full of zipped files (about 200). I would like to transform this into a folder consisting only of unzipped files. What would be the easiest and quickest way to do this?

Please note that I would like to remove the zipped file from the folder once it us unzipped.

Also, I'm on a Mac.

Thanks!

A: 

You can do something like:

for file in `ls *.zip`; do unzip -f $file; rm $file; done

We are looping through all the zip files in the directory, unzipping it and then deleting it.

Note that the -f option of zip will overwrite any file without prompting if it finds a duplicate.

You need to run the above one-line command on the command line from the directory that has the all the zip files. That one line is equivalent to:

for file in `ls *.zip` # ls *.zip gets the list of all zip file..iterate through that list one by one.
do             # for each file in the list do the following:
unzip -f $file # unzip the file.
rm $file       # delete it.
done
codaddict
Thanks! But it would be great if you could clarify the example a bit more (I'm somewhat of a novice). Do you run this on command line? And what does the ls in `ls*zip` mean? Thanks again :)
Eric Brotto
Okay, sounds good, but I just ran this from the command line and all I got was a blinking cursor with no action. Allow me to add that I've replaced ls*.zip with ls*.gz and unzip with gunzip. In other words I ran this: for file in `ls*.gz` do gunzip -f $file rm $file done. Any more help? :)
Eric Brotto
@codaddict. No worries, I got it. Thanks though! :)
Eric Brotto
A: 

I found this answer which is a simple one liner to gunzip all .gz compressed files within a folder.

Basically you cd to the folder and then run

gunzip *.gz

If you want to only unzip files with a certain prefix you put that before the *

gunzip example*.gz

Easy as cake!

Eric Brotto