aditiapratama
11/11/2015 - 1:49 AM

Batch zip and rename

Batch zip and rename

#!/bin/sh

## zip and rename
for dir in `ls`; do zip $dir $dir/*; mv $dir*zip $dir.cbz; done

## zip only
for dir in `ls`; do zip $dir $dir/*; done

## zip all files and folders in current directory
zip -r "${PWD##*/}.zip" *

## zip the contents of each folder from the current directory into an archive
for x in *; do if [ -d "$x" ]; then cd "$x"; zip -r "../$x.zip" *; cd ..; fi; done

## zip each folder into an archive
for x in *; do if [ -d "$x" ]; then zip -r "$x.zip" "$x"; fi; done

## another way to batch-zip
for i in $(find ./ -type d -maxdepth 1);do zip -r9 $i.zip $i; done

## same as above only using tar instead of zip
for i in $(find ./ -type d -maxdepth 1);do tar -czvf $i.tgz $i; done