Skip to content

Instantly share code, notes, and snippets.

@skatsuta
Last active May 5, 2016 09:58
Show Gist options
  • Save skatsuta/3c93158c5f765c82af24 to your computer and use it in GitHub Desktop.
Save skatsuta/3c93158c5f765c82af24 to your computer and use it in GitHub Desktop.
Zip each directory inside a given directory.
#!/usr/bin/env bash
# Show help
if [[ $1 = '--help' || $1 = '-h' ]]; then
echo "Usage: $0 [TARGET_DIR]"
echo "Zip each directory inside TARGET_DIR. If no argument is given, the current directory is regarded as TARGET_DIR."
exit 1
fi
# Zip each directory inside the given directory
TARGET_DIR=${1:=.}
cd "$TARGET_DIR"
for i in *; do
if [[ -d "$i" ]]; then
zip -r "$i".zip "$i"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment