歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux教程 >> 關於Unix/Linux下查看命令行歷史記錄(history/.bash_history)

關於Unix/Linux下查看命令行歷史記錄(history/.bash_history)

日期:2017/2/28 15:46:56   编辑:Linux教程

1.vi .bash_history

關於.bash_history的配置

export HISTCONTROL=ignoreboth

Don’t save duplicates

export HISTSIZE=10000

這個是針對history命令的設置,The number of commands to remember in the command history. The default value is 500.

export HISTFILESIZE=10000

這個是針對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.
export HISTIGNORE='ls'

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

以上的關於history的說明都可以使用man bash查的到,如果想要讓你的配置永久生效,可以把export命令寫到.bash_profile或者全局配置文件/etc/profile裡

2.history

模糊查詢,history | grep -i "xxx"

[Oracle@ www.linuxidc.com ~]$ history | grep -i "FND"
34 2012-07-04 01:29:15 history | grep -i "FND"
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"
36 2012-07-04 01:29:33 history | grep -i "FND"
[oracle@ www.linuxidc.com ~]$

如何讓history可以有時間戳顯示

# export HISTTIMEFORMAT='%F %T '

....

1027 2012-07-04 01:12:53 ls /etc/bash*
1028 2012-07-04 01:13:17 vi /etc/bashrc
1029 2012-07-04 01:16:04 history
[oracle@ www.linuxidc.com ~]$

清除history記錄

[oracle@ www.linuxidc.com ~]$ history -c
[oracle@ www.linuxidc.com ~]$ history
32 2012-07-04 01:20:40 history
[oracle@ www.linuxidc.com ~]$
注:清除history之後,.bash_history裡仍會有歷史記錄

如何不讓系統記錄歷史命令

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

3.使用Control+R來搜索命令

命令行中輸入Control+R,然後輸入過往命令的key word,你就很容易找到以前執行過的命令了

(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"
Copyright © Linux教程網 All Rights Reserved