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

 
(사용자 2명의 중간 판 25개는 보이지 않습니다)
1번째 줄: 1번째 줄:
*Bash history에 수행 시각 남기기
{{테스트|CentOS 5, CentOS 6}}
*bash_history 타임스탬프 찍기
{{테스트|우분투 14}}
 
==개요==
==개요==
~/.bash_history(즉 각 계정의 홈폴더의 .bash_history 파일)에는 수행한 명령어들이 기록된다.
;history with timestamp in linux
여기에 명령어를 수행한 시각을 기록하려면 /etc/profile.d 폴더에 bash_history.sh를 설정해주면 된다.
;Bash history에 수행 시각 남기기
;리눅스 history 시간 기록하기
;리눅스 HISTTIMEFORMAT 설정
;bash_history.sh
*~/.bash_history(즉 각 계정의 홈폴더의 .bash_history 파일)에는 수행한 명령어들이 기록된다.
*여기에 명령어를 수행한 시각을 기록하려면 /etc/profile.d 폴더에 bash_history.sh<ref>필자가 정한 스크립트 이름. 참고로 실제로 history가 기록되는 파일은 ~/.bash_history이다.</ref>를 설정해주면 된다.


==확인==
==사전 확인==
우선 bash_history.sh가 있는지 확인해보자.
우선 history에 일시가 표시되는지 확인해보자.
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@localhost ~]# ll /etc/profile.d/bash_history.sh
[root@zetawiki ~]# history
ls: /etc/profile.d/bash_history.sh: No such file or directory
... (생략)
</source>
  287  exit
없다.
  288  df -h
  289  ll
  290  history
  291  ll
  292  history
</syntaxhighlight>
:시각이 표시되지 않는다.


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


==확인 예시==
==확인 예시==
<source lang='dos'>
<syntaxhighlight lang='console'>
[root@localhost ~]# tail ~/.bash_history
[root@zetawiki ~]# tail ~/.bash_history
#1331168796
#1331168796
ll
ll
36번째 줄: 46번째 줄:
#1331169375
#1331169375
exit
exit
</source>
</syntaxhighlight>


<source lang='dos'>
<syntaxhighlight lang='console'>
[root@localhost ~]# history
[root@zetawiki ~]# history
... (생략)
... (생략)
  1022 2012-03-08 10:27:23 last
  990 [2012-03-08 11:15:52] exit
  1023  2012-03-08 10:27:25 last  | more
  991 [2012-03-08 10:06:36] ll
  1024  2012-03-08 10:28:13 history
  992 [2012-03-08 10:06:37] ll
  1025 2012-03-08 10:29:15 tail ~/.bash_history
  993 [2012-03-08 10:16:10] history
  1026 2012-03-08 10:29:37 history
  994 [2012-03-08 10:16:14] ll
  1027 2012-03-08 10:29:45 ll
  995 [2012-03-08 10:16:15] exit
</source>
  996 [2012-03-08 11:15:47] ll
  997 [2012-03-08 11:15:47] df -h
  998 [2012-03-08 11:15:49] exit
  999 [2012-03-08 11:15:55] history
</syntaxhighlight>
 
==같이 보기==
*[[history]]
*[[리눅스 나만의 설정]]
 
==주석==
<references/>
 
==참고==
*http://linux.byexamples.com/archives/467/list-command-line-history-with-timestamp/


[[분류: history]]
[[분류: /etc/profile.d]]
[[분류: /etc/profile.d]]
[[분류: Bash]]
[[분류: Bash]]
[[분류: CentOS]]
[[분류: Ubuntu]]

2020년 11월 27일 (금) 19:45 기준 최신판

1 개요[ | ]

history with timestamp in linux
Bash history에 수행 시각 남기기
리눅스 history 시간 기록하기
리눅스 HISTTIMEFORMAT 설정
bash_history.sh
  • ~/.bash_history(즉 각 계정의 홈폴더의 .bash_history 파일)에는 수행한 명령어들이 기록된다.
  • 여기에 명령어를 수행한 시각을 기록하려면 /etc/profile.d 폴더에 bash_history.sh[1]를 설정해주면 된다.

2 사전 확인[ | ]

우선 history에 일시가 표시되는지 확인해보자.

[root@zetawiki ~]# history
... (생략)
  287  exit
  288  df -h
  289  ll
  290  history
  291  ll
  292  history
→ 시각이 표시되지 않는다.

3 설정[ | ]

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

4 확인 예시[ | ]

[root@zetawiki ~]# tail ~/.bash_history
#1331168796
ll
#1331168797
ll
#1331169370
ll
#1331169374
ll
#1331169375
exit
[root@zetawiki ~]# 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] history
  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] df -h
  998  [2012-03-08 11:15:49] exit
  999  [2012-03-08 11:15:55] history

5 같이 보기[ | ]

6 주석[ | ]

  1. 필자가 정한 스크립트 이름. 참고로 실제로 history가 기록되는 파일은 ~/.bash_history이다.

7 참고[ | ]

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