본문 바로가기
Linux/쉘 스크립트

Linux 파일 용량 및 개수 파악 자동화 스크립트(폴더별 추출)

by 프리윙즈 2021. 10. 29.
728x90
반응형

파일이 너무 많을 때는 스크립트 진행시간이 너무 오래걸려서 결과물이 나올 때까지 기다리는게 너무 오래걸립니다.

이 스크립트는 지정한 폴더별로 결과값을 추출해 내는 스크립트입니다. 이 예시물은 총 16개 디렉토리를 스캔하고

16개의 결과물을 배출합니다.

 

폴더별로 추출하기 때문에 자동화가 끝난 결과물은 바로 바로 확인할 수 있습니다.

 

 

#!/bin/sh

rm -rf $PWD/exdat
mkdir exdat
cd exdat

path1="/exdat02/c20"
path2="/exdat03/C20"
path3="/exdat03/C30"
path4="/exdat03/C50"
path5="/exdat04/c10"

t1=$path1
t2=$path2
t3=$path3
t4=$path4
t5=$path5

file="du -sh"

d=$file

for exdat in $(seq 16)
do
echo >> $exdat.tx
echo >> $exdat.tx
echo "개수 용량    경로 " >> $exdat.tx
echo >> $exdat.tx
done


find $t1/FILING/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 1.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 1.tx >> exdat02_c20_FILING.txt

find $t2/* -type d |grep INSP | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 2.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 2.tx >> exdat03_C20_INSP.txt

find $t3/C31/* -type d| while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 3.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 3.tx >> exdat03_C30_C31.txt

find $t3/C32/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 4.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 4.tx >> exdat03_C30_C32.txt

find $t3/C37/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 5.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 5.tx >> exdat03_C30_C37.txt

find $t3/C38/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 6.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 6.tx >> exdat03_C30_C38.txt

find $t3/C39/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 7.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 7.tx >> exdat03_C30_C39.txt

find $t3/C40/* -type d| while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 8.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 8.tx >> exdat03_C30_C40.txt

find $t3/C41/* -type d| while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 9.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 9.tx >> exdat03_C30_C41.txt

find $t3/C42/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 10.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 10.tx >> exdat03_C30_C42.txt

find $t3/C47/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 11.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 11.tx >> exdat03_C30_C47.txt

find $t3/C48/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 12.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 12.tx >> exdat03_C30_C48.txt

find $t3/C50/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 13.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 13.tx >> exdat03_C30_C50.txt

find $t4/C51/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 14.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 14.tx >> exdat03_C50_C51.txt

find $t5/usedoc/* -type d c| while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 15.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 15.tx >> exdat04_c10_usedoc.txt

find $t5/bizdoc/* -type d | while read DIR N ; do   echo -n  ""; (find $DIR -type f -maxdepth 1 | wc -l);  ($d $DIR);  done  >> 16.tx
awk ' NR % 2 == 1 { printf "%s ", $0 } NR % 2 == 0 { print $0 } ' 16.tx >> exdat04_c10_bizdoc.txt



rm -rf *.tx

 

 

반응형

댓글