# history | more
1 2008-08-05 19:02:39 service network restart
2 2008-08-05 19:02:39 exit
3 2008-08-05 19:02:39 id
4 2008-08-05 19:02:39 cat /etc/redhat-release
2. 使用 Ctrl+R 搜索历史
(reverse-i-search)`red‘: cat /etc/redhat-release
[Note: Press enter when you see your command, which will execute the command from the history]
# cat /etc/redhat-release
Fedora release 9 (Sulphur)
1. 使用上方向键,并回车执行。
2. 按 !! 并回车执行。
3. 输入 !-1 并回车执行。
4. 按 Ctrl+P 并回车执行。
1 service network restart
2 exit
3 id
4 cat /etc/redhat-release
# !4
cat /etc/redhat-release
Fedora release 9 (Sulphur)
ps aux | grep yp
root 16947 0.0 0.1 36516 1264 ? Sl 13:10 0:00 ypbind
root 17503 0.0 0.0 4124 740 pts/0 S+ 19:19 0:00 grep yp
HISTSIZE=450
HISTFILESIZE=450
HISTFILE=/root/.commandline_warrior
# pwd
# pwd
# pwd
# history | tail -4
44 pwd
45 pwd
46 pwd [Note that there are three pwd commands in history, after executing pwd 3 times as shown above]
47 history | tail -4
# export HISTCONTROL=ignoredups
# pwd
# pwd
# pwd
# history | tail -3
56 export HISTCONTROL=ignoredups
57 pwd [Note that there is only one pwd command in the history, even after executing pwd 3 times as shown above]
58 history | tail -4
# pwd
# service httpd stop
# history | tail -3
38 pwd
39 service httpd stop
40 history | tail -3
# ls -ltr
# service httpd stop
# history | tail -6
35 export HISTCONTROL=erasedups
36 pwd
37 history | tail -3
38 ls -ltr
39 service httpd stop
[Note that the previous service httpd stop after pwd got erased]
40 history | tail -6
将 HISTCONTROL 设置为 ignorespace,并在不想被记住的命令前面输入一个空格:
space at the beginning of service, to ignore this command from history] # history | tail -3 67 ls
-ltr 68 pwd 69 history | tail -3
anaconda-ks.cfg
# vi !!:$
vi anaconda-ks.cfg
anaconda-ks.cfg
# vi -5 !^
vi anaconda-ks.cfg
# ls -l !cp:2
ls -l /really/a/very/long/path/long-filename.txt
ls -l /really/a/very/long/path/long-filename.txt
# history
# [Note that history did not display anything]
# export HISTIGNORE=”pwd:ls:ls -ltr:”
# pwd
# ls
# ls -ltr
# service httpd stop
# history | tail -3
79 export HISTIGNORE=”pwd:ls:ls -ltr:”
80 service httpd stop
81 history
[Note that history did not record pwd, ls and ls -ltr]