[L] history 명령어에 시간정보 포함하여 출력하기
💡 요약 정리
- CentOS 5.x 또는 CentOS 6.x 환경에서 동일하게 적용할 수 있습니다.
- history 명령어에 시간정보를 출력하려면 서버 시간을 먼저 정확히 설정해야 합니다.
- /etc/profile 파일에 HISTTIMEFORMAT을 설정하고 적용하면 됩니다.
1. 설치 환경
- CentOS 5.x x86 (64bit) / 6.x 환경도 동일함
2. 서버 시간 맞추기
history 명령어에 시간을 출력하기 앞서 현재 서버 시간을 정확하게 맞춰 줍니다.
[root@localhost /]# rdate -s time.bora.net
3. /etc/profile 파일 수정
/etc/profile 파일의 가장 하단에 다음과 같이 추가합니다.
[root@localhost /root]# vi /etc/profile
내용 추가 예시는 다음과 같습니다:
.
.
.
if [ -z "$INPUTRC" -a ! -f "$HOME/.inputrc" ]; then
INPUTRC=/etc/inputrc
fi
export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE INPUTRC
for i in /etc/profile.d/*.sh ; do
if [ -r "$i" ]; then
if [ "$PS1" ]; then
. $i
else
. $i >/dev/null 2>&1
fi
fi
done
unset i
unset pathmunge
# Add timestamp to .bash_history <------ 추가합니다
HISTTIMEFORMAT="%Y-%m-%d [%H:%M:%S] "
export HISTTIMEFORMAT