• File & Directory Tree
find . -print | sed -e 's;[^/]*/;|--;g;s;--|; |;g'
find ./201902 -print | sed -e 's;[^/]*/;|--;g;s;--|; |;g'

 

  • Diretory Tree
find . -type d -print | sed -e 's;[^/]*/;|--;g;s;--|; |;g'
ls -R |grep "^[.]/" | sed -e "s/:$//" -e "s/[^/]*[/]/--/g" -e "s/^/  |/"

 

  • 깨지는 파일 / 특수문자 파일명 삭제 하기
ls -li <- 파일 inodenumber 확인
find ./ -inum [inodenumber] -exec rm -i {} \;

 

  • directory 별 사이즈 확인
find ./ -type d -exec du -sk {} \;

 

  • 사이즈 순 정렬
find ./ -type d -exec du -sk {} \;| sort -rnk1
find ./ -type f -exec du -sk {} \;| sort -rnk1

 

  • 1일 이하 전 생성된(1일전부터 현재까지)
find ./ -type f -name '*.*' -ctime -1 -exec ls -l {} \;
  • 1일 이하 전 수정된(1일전부터 현재까지)
find ./ -type f -name '*.*' -mtime -1 -exec ls -l {} \;
find ./ -type f -name '*.*' -mtime 0 -exec ls -l {} \;

 

  • 1일 초과 2일 이하된 파일 만
find ./ -type f -name "*.*" -mtime 1 -exec ls -l {} \;

 

  • 1일 초과 된(1일 이전 까지)
find ./ -type f -name "*.tr*" -mtime +1 -exec rm -rf {} \;

 

  • 해당 파일보다 최근
find ./ -type f -newer TESTDB_cjq0_13125.trc -exec ls -l {} \;
  • SQL 문 찾기 (SELECT문)
-- Shell 스크립트
##
# Used : line_search.sh [file_name]
# SELECT로 시작하고 "\"로 끝나는 쿼리만 추출.
##
#파일 라인수
file_end=`wc -l $1|awk '{print $1}'`
#검색시작 라인
line_start=1  

#범위 검색 반복 Loop
while true
do
#추출 시작점 가져오기
head_start=`cat -n $1 | sed -n ${line_start},${file_end}p | grep SELECT | head -1 | awk '{print $1}'`
#추출 끝점 가져오기
head_end=`cat -n $1 | sed -n ${head_start},${file_end}p | grep \; | head -1 | awk '{print $1}'`

echo $head_start
echo $head_end

sed -n $head_start,${head_end}p $1
# 검색시작 라인 +1 (다음 검색시작점)
# line_start=`expr ${head_end} + 1`
line_start=$((head_end+1))

#파일끝과 검색시작이 같으면 종료
if [ ${file_end} -eq ${line_start} ]
then
        echo ${file_end}
        echo ${line_start}
        exit
fi
done

 

  • 업그레이드 한 내용
#!/bin/sh

file_end=`wc -l $1|awk '{print $1}'`
line_start=1  
head_start=${line_start}
head_end=${file_end}

get_line ()
{
        set -A arr_st
        set -A arr_en
        arr_st[0]=1

        i=1
        j=0
        for a in `grep -n -E "SELECT|UPDATE|INSERT" $1|cut -d ':' -f1`
        do
                arr_st[i]=`grep -n -E "SELECT|UPDATE|INSERT" $1|cut -d ':' -f1`
                arr_en[j]=`grep -n -E "param|dual|[)];" $1|cut -d ':' -f1`
                #i=`expr ${i} + 1`
                i=$((i+1))
                #j=`expr ${j} + 1`
                j=$((j+1))
        done
}

while true
do

    head_start=`cat -n $1 | sed -n ${line_start},${file_end}p | grep -i -E "SELECT|UPDATE|INSERT|DELETE" |grep -v EXECUTE | head -1 | cut -f1 | tr -d ' '`

    if [[ "${head_start}" = "" ]];
    then
            echo "2: head_start empty !"
            echo ${head_start}
            exit
    else
            #echo "->|"${head_start}"|"
            head_end=`cat -n $1 | sed -n ${head_start},${file_end}p | grep -i -E "order|group|where|[)]|dual|[)];"| head -1 | awk '{print $1}' | tr -d ' '`
            if [[ "${head_start}" = "${head_end}" ]];
            then
              #head_end=`expr ${head_start} + 0`
              head_end=$((head_start+0))
            else
              #head_end=`expr ${head_end}`
              head_end=$((head_start))
            fi
    fi

    sed -n $head_start,${head_end}p $1 | sed 's/^ *//g'

     if [[ "${head_start}" = "${head_end}" ]];
     then
       line_start=$((head_end+1))
     else
       line_start=$((head_end+2))
     fi

    if [ ${file_end} -eq ${line_start} ]
    then
            echo ${file_end}
            echo ${line_start}
            exit
    fi

done

'OS > 리눅스' 카테고리의 다른 글

find 명령어 사용  (0) 2023.11.15
서버 모니터링 vmstat 스크립트  (0) 2023.08.28
리눅스 백스페이스 ^? / ^H 해결법  (0) 2023.04.04
#!/bin/sh

print_usage() {
echo "Usage : $0 [interval][count]"
echo "interval : Number"
echo "count : Number"
exit 0;
}

result_tmp_file="/tmp/vmstat_result.$$"
result_file="vmstat_result.txt"
result_directory="./vmlog/"

if [ "$1" = "-help" ]
then
print_usage
fi

# interval check
if [ -z "$1" ]
then
interval=30
else
interval $1

if [ -n "`echo $interval | tr -d [0-9]`" ]
then
print_usage
else
interval=$1
fi
fi

if [ -n "$2" ]
then
if [ -n "`echo $2 | tr -d [0-9]`" ]
then
print_usage
else
count=$2
fi
fi

echo "####################################################################################################"
echo "# $0 Script"
echo "# Interval\t: $interval"
echo "# Count\t\t: $count"
echo "####################################################################################################"
# run...
echo "Running Start...."

cnt=0
while true
do
if [ ! -z "$count" ]
then
if [ $cnt -ge $count ]
then
break;
fi
fi

curr_date=`date +%Y/%m/%d`
filename_date=`date +%Y%m%d`

if [ -z "$old_date" -o "$old_date" != "$curr_date" ]
then
old_date=$curr_date
if [ !-d"$result_directory" ]
then
mkdir -p "$result_directory"
fi

echo "Date\tProc:r\tMEM:swap\tMEM:free\tPage:sr\tCPU:id\n">${result_directory}${filename_date}_${result_file}
fi

curr_time=` date +%H:%M:%S`
vmstat $interval 2 > $result_tmp_file



/* 각 OS의 결과에 맞게 수정이 필요함 */
cat $result_tmp_file | sed 1,3d | awk '($1+0==$1) {printf("%s%s\t%s\t%s\t%s\t%s\t%s\t%s\t%s\n","'"$curr_date"'","'"$curr_time"'", $1,$4,$5,$12,$16,$17,$18)}' >> ${result_directory}${filename_date}_${result_file}

echo "[$0] $curr_date$curr_time"

cnt=`expr $cnt + 1`
done

echo "Running End..."

'OS > 리눅스' 카테고리의 다른 글

find 명령어 사용  (0) 2023.11.15
포맷에 해당하는 라인만 표시하기  (1) 2023.11.15
리눅스 백스페이스 ^? / ^H 해결법  (0) 2023.04.04

리눅스에서 백스페이스가 안먹을 경우 .bash_profile 수정 이외에 해결방법 공유

 

프로젝트 수행 시 .bash_profile이나 설정 같은걸 임의로 함부로 바꿀 수 없기 때문에 이런식으로 해줘야 한다

 

-- erase 이후 이상하게 입력되는 특수기호 쓰기
stty erase ^?

물론 위에 stty는 접속할 때마다 다시 입력해줘야 한다ㅜㅜ

이게 귀찮다면 shift + backspace 같이 눌러주자!

 

 

'OS > 리눅스' 카테고리의 다른 글

find 명령어 사용  (0) 2023.11.15
포맷에 해당하는 라인만 표시하기  (1) 2023.11.15
서버 모니터링 vmstat 스크립트  (0) 2023.08.28

+ Recent posts