• 1132阅读
  • 1回复

关于Unix/Linux下查看命令行历史记录(history/.bash_history)

楼层直达
关于.bash_history的配置 .hZ =8y9  
export HISTCONTROL=ignoreboth YQe @C  
Don’t save duplicates I>G)wRpfR'  
export HISTSIZE=10000 Gf]oRNP,N  
QDxLy aL  
这个是针对history命令的设置,The number of commands to remember in the command history. The default value is 500. 7|65;jm+  
h'T\gF E%  
export HISTFILESIZE=10000 f~W.i]  
&t p5y}=n  
这个是针对history文件(.bash_history)的设置,The maximum number of lines contained  in  the  history file.  When this variable is assigned a value, the his-tory file is truncated, if necessary, by  removing  the oldest  entries, to contain no more than that number of lines.  The default value is 500.  The history file  is also  truncated  to  this size after writing it when an interactive shell exits. KLA nW#  
export HISTIGNORE='ls' =fG(K!AQ  
BAqu@F\):  
A colon-separated list of patterns used to decide which command lines should be saved on the history list.Each pattern is anchored at the beginning  of the line and must match the complete line <*4=sX@  
.[K{;^>  
以上的关于history的说明都可以使用man bash查的到,如果想要让你的配置永久生效,可以把export命令写到.bash_profile或者全局配置文件/etc/profile里 ~V5k  
@/|sOF;8W  
2.history Km\M /j|  
AO^F6Y/  
模糊查询,history | grep -i "xxx" b/ZX}<s(1=  
_k6N(c2Nd  
[oracle@bej301441 ~]$ history | grep -i "FND" Gg,,qJO  
   34  2012-07-04 01:29:15 history | grep -i "FND" E7*1QR{Q  
   35  2012-07-04 01:29:30 FNDLOAD apps/apps 0 Y DOWNLOAD $FND_TOP/patch/115/import/affrmcus.lct PT_CUSTOM_FUC.ldt FND_FORM_CUSTOM_RULES function_name="INV_INVTOMAI" Rs<,kMRGVL  
   36  2012-07-04 01:29:33 history | grep -i "FND" mHw1n=B  
[oracle@bej301441 ~]$ vuw1ycy)  
bh+R9~  
如何让history可以有时间戳显示 Y]P $|JW):  
I`5MAvP  
# export HISTTIMEFORMAT='%F %T ' .dM 0  
{9C(\i +  
.... M~ *E!  
1027  2012-07-04 01:12:53 ls /etc/bash* (y(V,kXwa8  
1028  2012-07-04 01:13:17 vi /etc/bashrc =E |[8 U)  
1029  2012-07-04 01:16:04 history BB>7%~3f  
[oracle@bej301441 ~]$ %/S BJ  
清除history记录 &;%+Hduc  
hpAIIgn  
[oracle@bej301441 ~]$ history -c ",~3&wx  
[oracle@bej301441 ~]$ history Bv9;q3]z-  
   32  2012-07-04 01:20:40 history ^P{'l^CVX  
[oracle@bej301441 ~]$ R` X$@iM  
注:清除history之后,.bash_history里仍会有历史记录 WpmypkJA#  
J'B;  
如何不让系统记录历史命令 ^g~-$t<!  
75^-93  
# export HISTSIZE=0 ;$|+H"g|  
# history  ym${4  
# [Note that history did not display anything] -lAA,}&+!  
,t)mCgbcO  
3.使用Control+R来搜索命令 y()#FRp7  
A:p0p^*  
命令行中输入Control+R,然后输入过往命令的key word,你就很容易找到以前执行过的命令了 XeZv%` ?  
(reverse-i-search)`FND': FNDLOAD apps/apps 0 Y DOWNLOAD $FND_TOP/patch/115/import/affrmcus.lct PT_CUSTOM_FUC.ldt FND_FORM_CUSTOM_RULES function_name="INV_INVTOMAI"
只看该作者 安逸沙发  发表于: 2017-09-10
linux查看历史命令history
1. history作用 Lhgs|*M  
TF,a `?c`  
linux的history命令的作用是,记录执行过的命令。 .aIFm5N3?  
用法: ui^v.YCMI  
history [n]  n为数字,列出最近的n条命令 ]"1\z>Hg  
-c  将目前shell中的所有history命令消除 ~U4;YlQP  
history [-raw] histfiles (WS<6j[q  
-a 将目前新增的命令写入histfiles, 默认写入~/.bash_history -_Iuvw  
-r  将histfiles内容读入到目前shell的history记忆中 7o M]qLF  
-w 将目前history记忆的内容写入到histfiles =~QC)y_  
[plain] view plain copy }4I;<%L3`  
shell > history   s!BZrVM%I`  
   34  14-10-28 16:19:24 ll   $S!WW|9j.  
   35  14-10-28 16:19:26 vim test   kC6s_k  
   36  14-10-28 16:19:33 ll   E;x~[MA  
   37  14-10-28 16:19:34 ll   5'O.l$)y  
展示3行 ,k3aeM~`%w  
[plain] view plain copy ?GGh )";y  
shell > history 3   QJ-?6 7_i  
1032  14-11-02 16:10:41 history   \\~4$Ai[  
1033  14-11-02 16:10:46 history |more   GB_ m&t  
1034  14-11-02 16:11:15 history 3   _`Sz}Yk  
使用! 执行历史命令。 '}wYSG-  
! number 执行第几条命令 *:A )j?(  
! command 从最近的命令查到以command开头的命令执行 }"?K Hy  
!! 执行上一条 6.'+y1yS)  
[plain] view plain copy f?C !Br}  
shell > !1046   YB}_zuZ4&  
history 3   \ o&i63u  
1045  14-11-02 16:22:38 head ~/.bash_history   ZvO:!u0+"  
1046  14-11-02 16:35:37 history 3   r4qFEFV3%  
1047  14-11-02 16:35:48 history 3   , 0rC_)&B  
shell > !!   K`2a{`  
history 3   Ic/<jFZXM  
1046  14-11-02 16:35:37 history 3   2h6F j&  
1047  14-11-02 16:35:48 history 3   #z t+U^#)  
1048  14-11-02 16:35:52 history 3   ,O(XNA(C  
shell > !head   ()>\D  
head ~/.bash_history   8LwbOR"  
#1414484377   1.H"$D>TC  
cd update/   I|O~F e.  
#1414484377   D_9/|:N:  
2. history配置修改 "5jZS6A]  
a4: PufS  
history记录的行数  (lPNMS|V  
[plain] view plain copy Wu Gm~<NS  
shell > echo $HISTSIZE   G%kXr$?W  
1000   SKfv.9  
shell >   #lLL5ji  
默认记录1000行 esu6iU@  
配置文件在/etc/profile中修改 >PGm}s_  
[plain] view plain copy W'0wTZG  
HISTSIZE=1000   Zz3#Kt5t3  
export  HISTSIZE   7T2W% JT-,  
历史命令文件记录在 ~/.bash_history中 =0]Mc$Ih  
O@=mN*<gg0  
想要让linux的history命令显示时间,history是默认不带时间, \qTNWA #'  
在/etc/profile 中增加 TwhK>HN  
[plain] view plain copy YI|G pq  
export HISTTIMEFORMAT="%y-%m-%d %H:%M:%S "   ;_SS3q  
查看.bash_history q7PRJX  
[plain] view plain copy z g j35  
shell > head ~/.bash_history   =Ffq =<  
#1414484377   g`6wj|@ =W  
cd update/   s*X\%!l9  
#1414484377   $^XPk#$m  
ll   3"hR:'ts  
#1414484388   2r0!h98  
vim address   8WGM%n#q  
#1414484439   S- \lN|  
ll   E!<$J^  
#1414484440   ~.lH)  
ll   zLqp@\sT  
shell >   -}sya1(<8  
.Topg.7W  
3. 同一账号同时多次登录写入history eM"mP&TTL  
kw~H%-,]  
普通情况下, 当以bash登录系统时,系统会从~/.bash_history读取以前运行的命令 zs:7!  
当注销时,把最新的1000(HISTSIZE)条命令更新到~/.bash_history文件中。 PZR%8 m}]u  
也可以使用history -w强制立刻写入,仅保留最新的。 7uxPkZbb  
z=_{jjs  
当同一账号,同时登录多个bash时,只有最后一个退出的会写入bash_history,其他的都被覆盖了。 L,pSdeq  
J-<B*ot+lX  
4. Ctrl+r 反向查询历史命令 cgeS)C7  
kte.E%.PE  
使用Ctrl+r反向查询历史命令,将匹配的最新一条显示出来 aQ:f"0fL  
如果还想继续向上查询,继续按Ctrl+r 7B!Qq/E?g  
[plain] view plain copy 5a!e%jj  
shell > history 3                                         VFSn!o:C  
1048  14-11-02 16:35:52 history 3   KBq aI((  
1049  14-11-02 16:36:11 head ~/.bash_history   qg{<&V7fE  
1050  14-11-02 16:41:05 history 3   I*S`I|{J  
(reverse-i-search)`his': head ~/.bash_history  
快速回复

限100 字节
安逸网提示:如果您提交过一次失败了,可以用”恢复数据”来恢复帖子内容
 
认证码:
上一个 下一个