특정 파일을 하위 디렉토리를 포함하여 찾아서 총 라인 수 세기

페이지 정보

profile_image
작성자 로빈아빠
댓글 0건 조회 6,584회 작성일 13-04-18 11:22

본문

리눅스 명령

$ find . "*.java" -print | xargs cat | wc -l <- 확장자가 java인 모든 파일을 찾아서총 라인수를 센다.


아래는 shell script

#!/bin/bash

wc_total=0

function cnt {
for file in `ls $1`; do
if [ -d $file ]; then
cnt $file
else
if [ "`file -b $file | grep -i '\(ascii\|text\)'`" != "" ]; then
let "wc_total += `cat $file | wc -l`"
fi
fi
done

}

cnt .
echo $wc_total
exit 0

댓글목록

등록된 댓글이 없습니다.