"리눅스 history 시간 기록하기"의 두 판 사이의 차이

26번째 줄: 26번째 줄:
==확인 예시==
==확인 예시==
<source lang='dos'>
<source lang='dos'>
[root@localhost ~]# tail ~/.bash_history
[root@jmnote ~]# tail ~/.bash_history
#1331168796
#1331168796
ll
ll
40번째 줄: 40번째 줄:


<source lang='dos'>
<source lang='dos'>
[root@localhost ~]# history
[root@jmnote ~]# history
... (생략)
... (생략)
   990  [2012-03-08 11:15:52] exit
   990  [2012-03-08 11:15:52] exit

2013년 10월 26일 (토) 16:32 판

history with timestamp in linux
Bash history에 수행 시각 남기기
리눅스 history 시간 기록하기

1 개요

~/.bash_history(즉 각 계정의 홈폴더의 .bash_history 파일)에는 수행한 명령어들이 기록된다. 여기에 명령어를 수행한 시각을 기록하려면 /etc/profile.d 폴더에 bash_history.sh를 설정해주면 된다.

2 확인

우선 bash_history.sh가 있는지 확인해보자.

[root@localhost ~]# ll /etc/profile.d/bash_history.sh
ls: /etc/profile.d/bash_history.sh: No such file or directory

→ 없다.

3 설정

  • 명령어를 수행할 때마다 현재시각을 기록하도록 한다.
  • 모든 계정에 적용되도록 퍼미션을 755로 변경한다.
echo export HISTTIMEFORMAT=\"[%F %T] \" > /etc/profile.d/bash_history.sh
chmod 755 /etc/profile.d/bash_history.sh
  • 설정 이후로 새로 로그인할 때부터 적용된다.

4 확인 예시

[root@jmnote ~]# tail ~/.bash_history
#1331168796
ll
#1331168797
ll
#1331169370
ll
#1331169374
ll
#1331169375
exit
[root@jmnote ~]# history
... (생략)
  990  [2012-03-08 11:15:52] exit
  991  [2012-03-08 10:06:36] ll
  992  [2012-03-08 10:06:37] ll
  993  [2012-03-08 10:16:10] ll
  994  [2012-03-08 10:16:14] ll
  995  [2012-03-08 10:16:15] exit
  996  [2012-03-08 11:15:47] ll
  997  [2012-03-08 11:15:47] ll
  998  [2012-03-08 11:15:49] exit
  999  [2012-03-08 11:15:55] history

5 같이 보기

6 참고 자료

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}