zoukankan      html  css  js  c++  java
  • Unix 下 history 命令设置 以及重复执行命令

    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@bej301441 ~]$ 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@bej301441 ~]$

    如何让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@bej301441 ~]$

    清除history记录

    [oracle@bej301441 ~]$ history -c
    [oracle@bej301441 ~]$ history
       32  2012-07-04 01:20:40 history
    [oracle@bej301441 ~]$
    注:清除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"

    转载请注明出处:http://blog.csdn.net/pan_tian/article/details/7715436

    如上想使用上次使用的命令,可以直接在提示符下敲( !!) (二个叹号) 则重复执行上次的命令。
    如果想使用往前数后几次的命令,一般先在提示符下敲 别名 “h“(查看历史命令),然后选择历史命令编号,

    在提示符下敲:(!历史命令编号)例如:(!36) 就执行这个session所记录的第36个命令。

    环境变量中需要有对history的设置以及对history的alias,这种方法一旦退出,别名不能保存
    set history = 50
    alias h 'history'

    如果需要保存别名,可在 ~/.bashrc文件中添加进去即可:

    # .bashrc
    alias h='history'

    # Source global definitions
    if [ -f /etc/bashrc ]; then
    . /etc/bashrc
    fi

  • 相关阅读:
    Python对JSON的操作 day3
    Python 文件操作 day2
    Python 字符串常用方法 day2
    Python字典 day2
    Python基础学习(day1)
    Excel图表转成图片
    hadoop —— MapReduce:统计访问所有独立IP个数 、 统计网站子目录访问次数 、 统计每个IP访问的子目录数
    Java -D命令对应的代码中获取-D后面的参数 和 多个参数时-D命令的使用
    hadoop —— teragen & terasort
    C# 计时器 以“天时分秒毫秒”形式动态增加显示
  • 原文地址:https://www.cnblogs.com/tonyxiao/p/14430079.html
Copyright © 2011-2022 走看看