龙盟编程博客 | 无障碍搜索 | 云盘搜索神器
快速搜索
主页 > 操作系统 > LINUX系统 >

linux下学习history命令的用法实例(2)

时间:2014-05-18 03:20来源:网络整理 作者:网络 点击:
分享到:
10.使用 HISTCONTROL 强制 history 不记住特定的命令 将 HISTCONTROL 设置为 ignorespace,并在不想被记住的命令前面输入一个空格: 代码如下: # export HISTCONTROL=ignor

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]

精彩图集

赞助商链接