프린트 하기

OS환경 : Oracle Linux 7.6 (64bit)

 

방법 : Oracle Linux 7 특정 날짜에 생성(수정)된 파일 갯수 확인

특정 날짜에 생성되거나 수정된 파일을 찾을일이 있어 찾아보다가 발견한 방법

 

 

방법 1. 일반 find 명령을 이용해 찾는 방법

특정 폴더로 이동 후 find 명령을 이용해 찾을수 있음

1
2
$ find . -type f -newermt "2023-07-06" | wc -l
10

 

 

갯수 체크 하는 wc -l 제거 후 확인

1
2
3
4
5
6
7
8
9
10
11
$ find . -type f -newermt "2023-07-06"
./.bash_history
./1
./work/newone.log
./.dbus/session-bus/acf160199c9b45a7a5bbf95e3f39d682-13
./lstrail.txt
./.Xauthority
./script/mondb_archdel.log
./.viminfo
./mondb/control03.ctl
./checkdatefile.sh

 

 

방법 2. 스크립트를 이용해 find 명령을 여러번 돌려 여러 날짜를 한번에 조회할수 있음

스크립트로 여러날짜 확인(find 를 여러번 수행하는 부하는 생각하고 실행해야함)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ cat checkfile.sh
#!/bin/bash
 
start_date="2023-05-01"
end_date="2023-05-10"
 
current_date=$(date -"$start_date" +%s)
end_timestamp=$(date -"$end_date" +%s)
 
while [[ "$current_date" -le "$end_timestamp" ]]; do
  current_date_string=$(date -d @"$current_date" +"%Y-%m-%d")
  file_count=$(find . -type f -newermt "$current_date_string" ! -newermt "$current_date_string + 1 day" | wc -l)
  echo "Date: $current_date_string, File Count: $file_count"
  current_date=$((current_date + 86400))  # 1일(86400초)을 더함
done

스크립트 설명

4번째 라인 : start_date와 end_date를 값으로 받아와서

7번째 라인 : date 명령어를 사용해 시작일과 종료일을 타임스탬프값으로 변환하고

10번째 라인 : $current_date와 $end_timestamp로 비교함(-le 는 "$current_date" <= "$end_timestamp" 라는 뜻)

12번째 라인 : find 명령 수행

13번째 라인 : echo 명령으로 해당일의 파일 개수 출력

14번째 라인 : current_date 변수를 타임스탬프로 유지하면서 날짜를 계속 증가시키며 반복

 

 

권한 부여 후 실행

1
2
3
4
5
6
7
8
9
10
11
12
$ chmod u+x checkfile.sh
$ sh checkfile.sh
Date: 2023-05-01, File Count: 3
Date: 2023-05-02, File Count: 1
Date: 2023-05-03, File Count: 0
Date: 2023-05-04, File Count: 3
Date: 2023-05-05, File Count: 0
Date: 2023-05-06, File Count: 0
Date: 2023-05-07, File Count: 0
Date: 2023-05-08, File Count: 0
Date: 2023-05-09, File Count: 0
Date: 2023-05-10, File Count: 0

 

 

참조 : 

https://chunggaeguri.tistory.com/entry/Shell-Script-%EB%B9%84%EA%B5%90-%ED%91%9C%ED%98%84%EC%8B%9D