Have you ever been using Mac or Linux and would like to unzip a directory full of zip files into the same directory? Chances are you have. Sure there are fancy GUI programs to unzip but most of them that I have found will just unzip the files into a directory with the name of the zip file, then after extraction you have to go into each directory and move the files up to the parent directory. I recently had this issue running on the Mac so to the command line I went. This is a very easy process when using the command line and anyone can do it. The following code is a BASH script that you would create inside the directory where all your zip files are. I will share the code and then explain how to use it and modify it to your liking.
#!/bin/sh
for zip in *.zip
do
unzip -o $zip
done
As you can see, very simple huh? What this literally does is looks at all the zip files in the directory and extracts them to the current working directory overwriting any files that may already be there. If you don’t want to overwrite any files and would prefer to be prompted anytime a duplicate files is changed, change the following line:
unzip -o $zip
to the following:
unzip $zip
To use the script, you will need to be at a command line and type “nano -w unpack” replacing unpack with whatever name you want to call it, paste the above code in there and save the file. Now in order to use it, you must type “chmod +x unpack” with again, replacing unpack with the name you chose. Now you can type “./unpack” in the directory where you saved the file with your zip files and it will unzip all files in the current directory.
This will now ask you every time a duplicate file is found what you would like to do. On the Mac I was presented with the option to either replace the file, replace all files in current zip files, replace none, or rename the file.
Keep in mind this will literally extract all files to current working folder, so if inside the zip files resides more folders, it will extract them as well. For instance, if you have a zip file that is a zipped up folder of “Applications” and inside “Applications” are 5 text files, the extracted 5 text files will be extracted into the folder “Applications”.
This tip is merely for the use of zip files that don’t have directories. For example, a zip file with 5 text files in the root of the zip files will be extracted to the same original folder as the zip file itself.
Hopefully you found this little tip useful.
Popularity: 2%









