开发者

Automated unzipping of files

开发者 https://www.devze.com 2023-01-17 22:41 出处:网络
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?

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开发者_如何学Python unzipped.

Also, I'm on a Mac.

Thanks!


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


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!

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号