본문 바로가기
RETRY/shellScript-ex

TAR 폴더 별 압축 하기

by 고민하는늘보™ 2017. 1. 8.
반응형

하기 내용은 

핀란드 헤이키님의 글 <2013.10.08 09:31 http://blog.daum.net/rayolla/486>

을 재구성이라기 보다는 Ctrl+C, Ctrl+V 한 내용입니다.


Linux 특정 폴더 상에 폴더 별 압축을 진행하는 shell script 입니다.


# vi tar_folder.sh


#!/bin/sh


DIRS=`ls -l $PWD | egrep '^d' | awk '{print $9}'`


# "ls -l $MYDIR"      = get a directory listing

# "| egrep '^d'"           = pipe to egrep and select only the directories

# "awk '{print $9}'" = pipe the result from egrep to awk and print only the 9th field


for DIR in $DIRS

do

    echo ${DIR}

    tar czvf ${DIR}.tar.gz ${DIR}

    #rm -rf ${DIR}

done



참고: http://moinne.com/blog/ronald/bash/list-directory-names-in-bash-shell

 

반응형