Linux – Compress Each Folder/Directory to Separate Archives

Lets say you’ve got a bunch of folders taking up a large swathe of space which you never really use but want to keep.

How can you easily compress them all up to individual archives of each folder?

#!/bin/bash

for folder in */

do
zip -r -9 “${folder%/}.zip” “$folder”
done

Save that to a file, chmod +x it and run in the location you want to compress the folders. Every folder (and all contents within) will be compressed to its own foldername.zip archive.

With zip, -9 is the flag for maximum compression.

Leave a Reply

Your email address will not be published. Required fields are marked *

*