BASH - 하위 폴더별로 압축파일 생성하기


회사 서버 내부의 폴더들을 각각 압축하여 보관해야 할 일이 생겨 급하게 뒤지다 만들어 본 소스임.

Prerequisite

  • Ubuntu package: zip

zipper.sh

#!/bin/bash
# Name: Zipper
# Description: Simple script to create separate archives for all subfolders within the
# root folder
# Creator: LILIS <[email protected]>
# 
# History:
#  V01 - DEC 2019 - LILIS
#        Initial release

ECHO "This script is to simply archive all subdirectories of a root folder
into separatte ZIP files."
ECHO "Place this script file at the root folder where target subdirectories
are placed in."
ECHO "If this script is not where it's should be, stop the script and place
it where it should be."

pause;

for i in */
do
	cd $I
	for j in */
	do
		zip -r "${j%/}.zip" "$j"
	done
	cd ..
done

별 건 아니지만 귀찮은 건 가능한한 단순하게 해결해보자는 잔머리굴리기에서 만들어봄.