Recovering front-end developer, now I just write JavaScript

Multiple Folders to Multiple Zips

How to create multiple zips from multiple folders

Multiple Folders to Multiple Zips
Photo by Garmin B / Unsplash

If you have a bunch of folders and want to individually zip them up, the simplest method is to right click and compress the folder. But, if you have many folders it can get tiresome.

I searched around and found a way to to run a small bash script that will loop through the top-level folders in a directory and create a zip from it.

For example, say you have:

Main folder:
  - MyFolder
  - Another Folder
  - Yet more folder

cd into the main folder, cd Main\ folder and then run one of the below:

# Loud mode
for i in */; do zip -r "${i%/}.zip" "$i"; done

# Quiet mode
for i in */; do zip -q -r "${i%/}.zip" "$i"; done

The result of the above is:

Main folder:
  - MyFolder
  - MyFolder.zip
  - Another Folder
  - Another Folder.zip
  - Yet more folder
  - Yet more folder.zip

I was using this to backup a load of working files and it worked a charm.

Happy archiving!