2013年7月11日 星期四

linux-histry

linux
history
!123
pgup


http://linuxtoy.org/archives/history-command-usage-examples.html
# export HISTCONTROL=ignoredups        ## set to not duplicate
# export HISTTIMEFORMAT='%F %T '  ## Display Format
# export HISTSIZE=0  ## Not Record
# export HISTIGNORE=”pwd:ls:ls -ltr:” ## Not record this command e.g. [pwd、ls、ls -ltr]
# history -c   ## clear all history
# uparrow or !! or !ps or ctrl+P  or !-1  ## 4 method run the last history
# vi ~/.bash_profile
HISTSIZE=450  ## set history size
HISTFILESIZE=450 ## set history size
HISTFILE=/root/.bash_history  ## history file






使用 Ctrl+R 搜索?史
Ctrl+R 是我?常使用的一?快捷?。此快捷??你?命令?史?行搜索,?于想要重复?行某?命令的?候非常有用。?找到命令后,通常再按回??就可以?行?命令。如果想?找到的命令?行?整后再?行,?可以按一下左或右方向?。


# [Press Ctrl+R from the command prompt, which will display the reverse-i-search prompt]
(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)




使用 HISTCONTROL ?命令?史中剔除??重复的?目

使用 HISTCONTROL 清除整?命令?史中的重复?目

上例中的 ignoredups 只能剔除??的重复?目。要清除整?命令?史中的重复?目,可以? HISTCONTROL ?置成 erasedups:


# export HISTCONTROL=erasedups
# 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 ?制 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
使用 -c ??清除所有的命令?史

如果你想清除所有的命令?史,可以?行:

# history -c
命令替?

在下面的例子里,!!:$ ???前的命令?得上一?命令的??:
# ls anaconda-ks.cfg
anaconda-ks.cfg
# vi !!:$
vi anaconda-ks.cfg
?充:使用 !$ 可以?到同?的效果,而且更??。[感? wanzigunzi ?者?充]
下例中,!^ ?上一?命令?得第一???:
# cp anaconda-ks.cfg anaconda-ks.cfg.bak
anaconda-ks.cfg
# vi -5 !^
vi anaconda-ks.cfg

?特定的命令替?指定的??

在下面的例子,!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

使用 HISTSIZE 禁用 history

如果你想禁用 history,可以? HISTSIZE ?置? 0:


# export HISTSIZE=0
# history
# [Note that history did not display anything]


沒有留言:

張貼留言