date 의 다양한 표현들

On 2006-04-12, in 잡동사니/IT일반, 서버, by !엔죠라이프

date “+%Y-%m-%d”
2006-01-05

date “+%Y-%m-%d %H:%m”
2006-01-05 16:01

date “+%w”
4 -> 목요일

date -R –date “1 days ago”
Wed, 4 Jan 2006 16:07:31 +0900

date -R
Thu, 5 Jan 2006 16:07:40 +0900

date
2006. 01. 05. (목) 16:07:47 KST

date -R “+%d/%b/%Y”
05/Jan/2006 access_log 의 날짜형식

date -R “+%d/%b/%Y” –date “1 days ago”
04/Jan/2006 access_log 의 날짜형식(하루전)

date -R “+%a %b %e” | awk ‘{printf(“%s %s %2d\n”, $1,$2,$3)}’
Thu Jan 5 xferlog 의 날짜형식

date -R “+%a %b %e” –date=”1 days ago”| awk ‘{printf(“%s %s %2d\n”, $1,$2,$3)}’
Thu Jan 4 xferlog 의 날짜형식(하루전)

응용)

access_log 에서 오늘짜 로그만 추출
cat /var/log/httpd/access_log | grep $(date -R “+%d/%b/%Y”) |less

xferlog 에서 오늘짜 로그만 추출
tac /var/log/xferlog|grep “$(date -R “+%a %b %e” | awk ‘{printf(“%s %s %2d\n”, $1,$2,$3)}’)”|less

Tagged with:  

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>