linux下学习history命令的用法实例(2)
10.使用 HISTCONTROL 强制 history 不记住特定的命令
将 HISTCONTROL 设置为 ignorespace,并在不想被记住的命令前面输入一个空格:
# export HISTCONTROL=ignorespace
# ls -ltr
# pwd
# service httpd stop [Note that there is a space at the beginning of service, to ignore this command from history]
# history | tail -3
67 ls -ltr
68 pwd
69 history | tail -3
11.使用 -c 选项清除所有的命令历史
如果你想清除所有的命令历史,可以执行:
# history -c
12.命令替换
在下面的例子里,!!:$ 将为当前的命令获得上一条命令的参数:
# ls anaconda-ks.cfg
anaconda-ks.cfg
# vi !!:$
vi anaconda-ks.cfg
补充:使用 !$ 可以达到同样的效果,而且更简单。
下例中,!^ 从上一条命令获得第一项参数:
# cp anaconda-ks.cfg anaconda-ks.cfg.bak
anaconda-ks.cfg
# vi -5 !^
vi anaconda-ks.cfg
13.为特定的命令替换指定的参数
在下面的例子,!cp:2 从命令历史中搜索以 cp 开头的命令,并获取它的第二项参数:
# cp ~/longname.txt /really/a/very/long/path/long-filename.txt
# ls -l !cp:2
ls -l /really/a/very/long/path/long-filename.txt
下例里,!cp:$ 获取 cp 命令的最后一项参数:
# ls -l !cp:$
ls -l /really/a/very/long/path/long-filename.txt
14.使用 HISTSIZE 禁用 history
如果你想禁用 history,可以将 HISTSIZE 设置为 0:
# export HISTSIZE=0
# history
# [Note that history did not display anything]
15.使用 HISTIGNORE 忽略历史中的特定命令
下面的例子,将忽略 pwd、ls、ls -ltr 等命令:
# 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]
- 上一篇:dd使用方法详解
- 下一篇:linux下查询history操作时间的方法