2012.03.09 03:33
리눅스 서버에서 일반적으로 history 라는 명령어를 통해서 로그인한 사용자가
작업했던 커맨드를 확인할 수 있습니다.
1. SHELL 마다 각기 다른 HISTFILE이 지정되는데,
Redhat Linux 계열에서 Default SHELL은 BASH이며 HISTFILE은 아래와 같습니다.
~/.bash_history
로그인한 순간부터의 입력한 커맨드는 버퍼에 기록되며,
로그아웃시 버퍼에 기록된 history는 ~/.bash_history 파일에 추가 기록이 됩니다.
2. history 라는 명령어를 입력하면 ~/.bash_history 와 buffered/cache history 가
아래와 같이 화면에 나열됩니다.
[root@rootnya root]# history
204 dmesg
205 clear
206 df -TH
207 ls -alR /var/tmp
208 ls -alR /tmp
209 cd /var/tmp
210 clear
211 ls -la
212 rm -f rpm-tmp.64248
213 clear
214 ls -la
215 clear
216 ls -al
217 history
[root@rootnya root]#
출력된 결과를 살펴보면 Column 1 은 ~/.bash_history 와 buffered/cache history 에
저장된 커맨드의 히스토리 순번이며 Column 2 은 입력하였던 명령어들이다.
그러나, 정작 언제(명령어를 입력한 시각)라는 항목은 보이지 않고 있습니다.
3. bash 에서는 다양한 HIST 변수를 지정할 수 있습니다.
man bash 후 /HISTTIMEFORMAT 이라는 변수를 조회해보면,
우리가 알고 싶은 명령어를 입력한 시간을 hostory 에 남길 수 있는 방법을 제시하고 있습니다.
HISTTIMEFORMAT
If this variable is set and not null, its value is used as a format string for strftime(3)
to print the time stamp associated with each history entry displayed by the history builtin.
If this variable is set, time stamps are written to the history file so they may be preserved
across shell sessions. HOME The home directory of the current user; the default
argument for the cd builtin command.
The value of this variable is also used when performing tilde expansion.
4. HIST 변수의 적용은 /etc/profile 파일에 아래와 같은 라인을 추가합니다.
# Add timestamp to .bash_history
HISTTIMEFORMAT="%Y-%m-%d_%H:%M:%S "
export HISTTIMEFORMAT
위와 같이 /etc/profile 파일에 추가 후 source /etc/profile 또는 ssh 로 재로그인 후 부터는
history 명령어 입력시 Column 2 에 연/월/일/시/분/초 의 시간 정보를 확인할 수 있습니다.
[root@rootnya root]# history
959 2007-06-23_02:08:59 vi /home/com/www/bbs/skin/member_list/list_main.php
960 2007-06-23_02:10:00 ps aux
961 2007-06-23_02:10:01 ps ax
962 2007-06-23_05:24:47 vi /etc/procmailrc
963 2007-06-23_05:25:07 /etc/init.d/qmail reload
964 2007-06-23_05:25:08 ps aux
965 2007-06-23_05:25:11 /etc/init.d/qmail restart
966 2007-06-23_05:25:12 ps aux
967 2007-06-23_05:25:20 tail -f /var/log/qmail/procmail
968 2007-06-23_05:25:31 vi /etc/procmailrc
969 2007-06-23_05:25:39 /etc/init.d/qmail restart
970 2007-06-23_05:25:47 vi /var/log/qmail/procmail
971 2007-06-23_05:26:38 vi /etc/procmailrc
972 2007-06-23_05:26:49 /etc/init.d/qmail restart
[root@rootnya root]# history
단, bash-3.0-alpha 이상의 bash 부터 HISTTIMEFORMAT 변수를 지원합니다.
이전 버전의 bash 는 위 이상의 버전으로 업데이트 후 부터 지원이 됩니다.
번호 | 제목 | 글쓴이 | 날짜 | 조회 수 |
---|---|---|---|---|
246 | debian / ubuntu 에서 ntsysv(rcconf) 사용하기 | 호스트웨이 | 2012.11.01 | 18270 |
245 | 리눅스 파티션 볼륨 레이블 설정 | 호스트웨이 | 2012.11.01 | 3180 |
244 | Web site에서 php error log 출력하지 않기 | 호스트웨이 | 2012.11.01 | 5048 |
243 | 리눅스 wc 명령어 | 호스트웨이 | 2012.10.26 | 3476 |
242 | TCp syn Flooding 공격시 대처방법 TIP | 호스트웨이 | 2012.10.26 | 2240 |
241 | 리눅스 du 사용법 | 호스트웨이 | 2012.10.25 | 17855 |
240 | 리눅스 시스템상에서 하드웨어사양 확인 | 호스트웨이 | 2012.10.24 | 2372 |
239 | ls 명령어의 파일 사이즈 쉽게 확인하기 | 호스트웨이 | 2012.10.23 | 177942 |
238 | history 삭제 막기 | 호스트웨이 | 2012.10.19 | 3974 |
237 | Disk I/O 줄이기 | 호스트웨이 | 2012.10.18 | 18480 |
236 | 리눅스 tac 명령어를 통해 파일내용 역순으로 출력하기 | 호스트웨이 | 2012.10.18 | 4497 |
235 | 리눅스 파일명 일괄변경하기 | 호스트웨이 | 2012.10.18 | 4469 |
234 | VNC-server 설치 및 설정 | 호스트웨이 | 2012.10.12 | 4156 |
233 | lrzsz 사용해보기 | 호스트웨이 | 2012.10.12 | 6066 |
232 | 문자열 치환하기 | 호스트웨이 | 2012.10.12 | 12662 |
231 | ispell 명령어를 통한 철자 검사 및 수정하기 | 호스트웨이 | 2012.10.12 | 2523 |
230 | 리눅스 vsftp 자세한 log남기는 설정 | 호스트웨이 | 2012.10.11 | 18087 |
229 | ssh port 번호 변경하기 | 호스트웨이 | 2012.10.05 | 16491 |
228 | /dev/null 과 /dev/zero의 차이 | 호스트웨이 | 2012.10.05 | 4307 |
227 | fstab 손상으로 / 파티션이 Read-Only 상태일 때 Remount 하는 방법 | 호스트웨이 | 2012.10.05 | 30761 |