다음 스크립트는 명령 행에 지정된 모든 파일의 날짜를 확인합니다.
그것은의 GNU 버전을 필요로 sed
, date
및stat
$ cat check-dates.sh
#! /bin/bash
for f in "$@" ; do
# get date portion of filename
fdate=$(basename "$f" .txt | sed -re 's/^.*(2015)/\1/')
# convert it to seconds since epoch + 1 day
fsecs=$(echo $(date +%s -d "$fdate") + 86400 | bc )
# get modified timestamp of file in secs since epoch
ftimestamp=$(stat -c %Y "$f")
[ "$ftimestamp" -gt "$fsecs" ] && echo "$f has been modified after $fdate"
done
$ ./check-dates.sh file-name-20151002.txt
file-name-20151002.txt has been modified after 20151002
$ ls -l file-name-20151002.txt
-rw-rw-r-- 1 cas cas 0 Oct 26 19:21 file-name-20151002.txt
온라인 매뉴얼 페이지를 올바르게 읽으면 테스트되지 않았지만 Mac (및 FreeBSD 등)에서 작동 해야하는 버전이 있습니다.
#! /bin/bash
for f in "$@" ; do
# get date portion of filename
fdate=$(basename "$f" .txt | sed -e 's/^.*\(2015\)/\1/')
# convert it to seconds since epoch + 1 day
fsecs=$(echo $(date -j -f %Y%m%d "$fdate" +%s) + 86400 | bc )
# get modified timestamp of file in secs since epoch
ftimestamp=$(stat -f %m "$f")
[ "$ftimestamp" -gt "$fsecs" ] && echo "$f has been modified after $fdate"
done