How to compress multiple folders, each into its own zip archive?
bash, command-line, linux, terminal
Solution
for i in *
do
[ -d "$i" ] && zip -r "$i.zip" "$i"
done
You walk through all the directories and create zip for each of them.
Or even more concise:
for i in */; do zip -r "${i%/}.zip" "$i"; done
(thanks to damienfrancois for suggestion).
Problem
So I want to create a script that enables me to compresses each folder into its own zip archive and not into a one big zip file. As an example, I've got a directory: ``` + MyDirectory/ | | | + Folder_01/ | | | + Folder_02/ | | | + Folder_03/ | ``` When I'm done running the script under `MyDirectory` then I would have a zip file of each Folder which is inside `MyDirectory`: `Folder_01.zip`, `Folder_02.zip` and `Folder_03.zip`. I know some BASH but this is something I can't figure out. How can this be done? Kind regards.