history 명령어 사용법

//history 명령어 사용법

history 명령어 사용법

리눅스 관련내용중 history 명령어에 관한 내용입니다.
history는 많이 알려진 명령어이기도 해서 자주사용하지는 않지만 알아두면 편리한 기능위주로 정리해놓았습니다.

먼저 history명령어는 일정갯수 이상 사용했던 명령어를 특정파일에 저장해두고 확인하거나 필요할때 다시 불러서 사용하기위해 필요한 명령어입니다.
# echo $HISTSIZE
50000
쉘변수인 HISTSIZE는 명령어를 갯수를 지정하는 변수입니다.
저장파일 위치는 /각계정의홈폴더/.bash_histoty 에 있습니다.
# ls -la /root/.bash_history
-rw——- 1 root root 1275092 Dec 20 18:57 /root/.bash_history

1.저장된 명령어 탐생하는 방법
(예시1)
# history
1 2018-12-21_13:40:57\ cp workers.properties workers.properties.back2
2 2011-12-28_14:57:03\ cp workers.properties.back workers.properties
3 2011-12-28_14:57:09\ /usr/local/apache/bin/apachectl restart
4 2011-12-28_14:58:27\ vi workers.properties
5 2011-12-28_14:59:04\ vi workers.properties.back

49992 2018-12-21_14:08:37\ ls -la /root/.bash_history
49993 2018-12-21_14:11:19\ history
49994 2018-12-21_14:11:25\ history | more
49995 2018-12-21_14:12:05\ history | more
49996 2018-12-21_14:12:09\ history

일반적으로 사용하는 방법입니다.
(예시2)
# history | grep find
373 2011-12-28_15:43:39\ find -name /
408 2011-12-28_15:44:35\ find -name / server.xml
411 2011-12-28_15:46:28\ find /usr/local/src/ -name server.xml
406 2012-01-04_12:47:36\ ls -la find

46342 2018-01-20_16:52:38\ find / -name mod_url*
47076 2018-02-09_12:12:53\ find / -name cband
47556 2018-03-23_17:03:30\ find /dev -type f
49566 2018-11-12_19:43:59\ find / -name mysql.os
49567 2018-11-12_19:44:02\ find / -name mysql.so
49988 2018-12-22_17:11:16\ history | grep find | more
49989 2018-12-22_17:12:49\ history | grep find

2.명령어를 재사용하는 방법
키보드의 위아래쪽 화살표키를 이용하면 이미 사용했던 명령어들을 확인하고 재실행할수 있습니다.
사용하고자하는 명령어가 너무 예전에 사용한것일 경우 ‘history | grep find | more’ 등의 명령으로 목록을 확인한후 드레그로 필요한 명령어를 복사하고 우클릭으로 붙여넣기가 가능합니다.

마우스 지원이 안되는 콘솔에서 history 명령으로 필요한 명령어를 사용하고자 할경우
(예시2)의 목록에서 보면 좌측에 있는 번호를 “!번호”와 같은 형식으로 실행이 가능합니다.
# !49989
이렇게 하면 49989에 사용했던 history | grep find 라는 명령이 재사용됩니다.

감사합니다.

By |2019-08-12T16:55:39+00:0012월 22nd, 2018|Categories: linux|Tags: , , , |0 Comments

About the Author: