• 1130阅读
  • 1回复

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

楼层直达
关于.bash_history的配置 ECsb?n7e  
export HISTCONTROL=ignoreboth j'x@P+A  
Don’t save duplicates G#L6;  
export HISTSIZE=10000 Aflf]G1  
QVF561Yz  
这个是针对history命令的设置,The number of commands to remember in the command history. The default value is 500. /&H l62Ak  
w1EB>!<;tj  
export HISTFILESIZE=10000 v4]#Nc$~T  
hbe";(  
这个是针对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. kXWC o6?  
export HISTIGNORE='ls' lDL(,ZZS`  
$a|>>?8  
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 gj7'4 3 ?W  
_VB;fH$  
以上的关于history的说明都可以使用man bash查的到,如果想要让你的配置永久生效,可以把export命令写到.bash_profile或者全局配置文件/etc/profile里 BXNC(^  
3!h3flE  
2.history dUBf.2 ry  
F=?GV\Tw  
模糊查询,history | grep -i "xxx" *Z+U}QhHD6  
>[N6_*K]  
[oracle@bej301441 ~]$ history | grep -i "FND" sY[!=`@  
   34  2012-07-04 01:29:15 history | grep -i "FND" o{' J O3  
   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" M<x><U#]A  
   36  2012-07-04 01:29:33 history | grep -i "FND" a# Uk:O!  
[oracle@bej301441 ~]$ F ~e}=Nb  
@.=2*e.z|b  
如何让history可以有时间戳显示 "HLh3L~  
;xSlRTNT=6  
# export HISTTIMEFORMAT='%F %T ' % C)|fDwN  
u$ vLwJ|o  
.... H:t2;Z'  
1027  2012-07-04 01:12:53 ls /etc/bash* rm<`H(cT  
1028  2012-07-04 01:13:17 vi /etc/bashrc :U faMe5  
1029  2012-07-04 01:16:04 history }]pOR&o  
[oracle@bej301441 ~]$ m xy=3cUi  
清除history记录 kqCUr|M.P  
O_D;_v6Ii+  
[oracle@bej301441 ~]$ history -c K&&YxX~ 3  
[oracle@bej301441 ~]$ history K14{c1  
   32  2012-07-04 01:20:40 history <$ %Y#I'zX  
[oracle@bej301441 ~]$ 6w0r)  
注:清除history之后,.bash_history里仍会有历史记录 (k %0|%eR  
Bs-MoT!  
如何不让系统记录历史命令 =Y R+`[bfI  
-:V2Dsr6;  
# export HISTSIZE=0 PLWx'N-kqL  
# history i^/D_L.  
# [Note that history did not display anything] g@S?5S.Av  
I\VC2U  
3.使用Control+R来搜索命令 RTYhgq  
M+\LH  
命令行中输入Control+R,然后输入过往命令的key word,你就很容易找到以前执行过的命令了 S]DYEL$  
(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作用 fP V n;  
,T`,OZm  
linux的history命令的作用是,记录执行过的命令。 EG;E !0  
用法: Pal=I)  
history [n]  n为数字,列出最近的n条命令 XS">`9o!  
-c  将目前shell中的所有history命令消除 -X~mW  
history [-raw] histfiles i*Ldec^  
-a 将目前新增的命令写入histfiles, 默认写入~/.bash_history P=5+I+  
-r  将histfiles内容读入到目前shell的history记忆中 lU%}_!tp3/  
-w 将目前history记忆的内容写入到histfiles L_NiU;cr%  
[plain] view plain copy ylKK!vRHT  
shell > history   8s@N NjV  
   34  14-10-28 16:19:24 ll   DzQBWY] )  
   35  14-10-28 16:19:26 vim test   0(D^NtB7  
   36  14-10-28 16:19:33 ll   ba);f[>  
   37  14-10-28 16:19:34 ll   \A"o[A2v  
展示3行 ^ RA'E@ "  
[plain] view plain copy `t&{^ a&Y"  
shell > history 3   Xq*^6*E-}  
1032  14-11-02 16:10:41 history   Ki\.w~Qs  
1033  14-11-02 16:10:46 history |more   /|1p7{km  
1034  14-11-02 16:11:15 history 3   Nr4:Gih  
使用! 执行历史命令。 h'):/}JPl  
! number 执行第几条命令 \^c4v\s<o#  
! command 从最近的命令查到以command开头的命令执行 GiV %Hcx  
!! 执行上一条 =|S%Rzsk  
[plain] view plain copy 8Xot ly  
shell > !1046   BBB@M  
history 3   F4EAC|Y  
1045  14-11-02 16:22:38 head ~/.bash_history   tS'lJu  
1046  14-11-02 16:35:37 history 3   Fb5U@X/vE  
1047  14-11-02 16:35:48 history 3   EKwQ$?I  
shell > !!   =ejj@c  
history 3   Ps!MpdcL3  
1046  14-11-02 16:35:37 history 3   ]pax,| +$C  
1047  14-11-02 16:35:48 history 3   :Ha/^cC/3  
1048  14-11-02 16:35:52 history 3   " O&93#8  
shell > !head   ?+yr7_f3*  
head ~/.bash_history   Bt+^H6cb  
#1414484377   `ONjEl  
cd update/   *o6}>;  
#1414484377   ;[v!#+yml  
2. history配置修改 CdolZW-!"  
{ i5?R,a)  
history记录的行数 9 BCW2@Kp  
[plain] view plain copy bjZJP\6  
shell > echo $HISTSIZE   "[bkdL<  
1000   88g3<&  
shell >   S* h52li  
默认记录1000行 NVyBEAoh  
配置文件在/etc/profile中修改 ]g_VPx"  
[plain] view plain copy H|9t5   
HISTSIZE=1000   h<9s& p  
export  HISTSIZE   wq)*bIv  
历史命令文件记录在 ~/.bash_history中 48^-]};  
i Ha?b2=)  
想要让linux的history命令显示时间,history是默认不带时间, 5E!C?dv(z  
在/etc/profile 中增加 e~r/!B5X  
[plain] view plain copy UhxM85M;x  
export HISTTIMEFORMAT="%y-%m-%d %H:%M:%S "   j-<]OOD  
查看.bash_history _&<n'fK[  
[plain] view plain copy 7v: XAU  
shell > head ~/.bash_history   +8Xjk\Hi  
#1414484377   L2}\Ah"[  
cd update/   ]\, ?u /  
#1414484377   v"*r %nCi  
ll   IH|zNg{\Y  
#1414484388   5ggyk0  
vim address   VB |?S|<  
#1414484439   3CCs_AO  
ll   v{u3[c   
#1414484440   i~@gI5[k+  
ll    H.5 6  
shell >   wNB?3v{n  
U2Ve @.  
3. 同一账号同时多次登录写入history #S>N}<>  
pF;.nt)  
普通情况下, 当以bash登录系统时,系统会从~/.bash_history读取以前运行的命令 B'Yx/c&n  
当注销时,把最新的1000(HISTSIZE)条命令更新到~/.bash_history文件中。 (,At5 T  
也可以使用history -w强制立刻写入,仅保留最新的。  f<o|5r  
z)Rkd0/X  
当同一账号,同时登录多个bash时,只有最后一个退出的会写入bash_history,其他的都被覆盖了。 d59rq<yI  
x{H+fq,M  
4. Ctrl+r 反向查询历史命令 e$L C  
3.Fko<D4jD  
使用Ctrl+r反向查询历史命令,将匹配的最新一条显示出来 {_7hX`p  
如果还想继续向上查询,继续按Ctrl+r 1P)K@j  
[plain] view plain copy G^'We6<  
shell > history 3                                         6(rm%c  
1048  14-11-02 16:35:52 history 3   ZayJllaq^  
1049  14-11-02 16:36:11 head ~/.bash_history   xI,3(A.  
1050  14-11-02 16:41:05 history 3   enk`I$Xx  
(reverse-i-search)`his': head ~/.bash_history  
快速回复

限100 字节
安逸网提示:批量上传需要先选择文件,再选择上传
 
认证码:
上一个 下一个