zoukankan      html  css  js  c++  java
  • history命令

    history是系统内建命令,查看帮助方法如下:

    # help history
    

    用法:

    history [-c] [-d offset] [n] or history -anrw [filename]
    

    常用选项:

    -c:clear the history list by deleting all of the entries. 清空history list。可以用 -r 选项再读回来。
    -d offset:delete the history entry at offset OFFSET. 删除指定的命令历史。
    -a:append history lines from this session to the history file. 将新增的history追加到history file。
    -r:read the history file and append the contents to the history list. 从history file读取命令并追加到history list。
    -n:read all history lines not already read from the history file.
    -w:write the current history to the history file and append them to the history list. 将当前的history写入history file。
    

    1、显示最近10条命令历史

    # history 10 
    

    2、重复执行第N条命令
    # !n

    重复执行倒数第N条命令
    # !-n

    重复执行上一条命令
    # !!

    3、重复执行最近一条以string开头的命令
    # !string

    4、调用上一条命令的最后一个参数:

    a、快捷键:ESC+.
    b、字符串:!$
    
    # ls /etc/sysconfig/network-scripts/ifcfg-eno16777736
    # vim !$ 
    

    5、定制history的功能,可通过环境变量实现

    5.1、HISTSIZE:history可保留的命令历史的条数。如果这个值设置为0,则不记录history。
    5.2、HISTFILE:命令历史文件位置。默认为 .bash_history,清空或者删除该文件,可以清除命令历史记录。
    5.3、HISTFILESIZE:命令历史记录条数。(.bash_history文件)
    5.4、HISTTIMEFORMAT:显示时间

    # export HISTTIMEFORMAT='%F %T '
    

    5.5、HISTCONTROL:控制命令历史记录

    HISTCONTROL=ignoredups:忽略连续重复的命令。
    HISTCONTROL=ignorespace:忽略以空白字符开头的命令。
    HISTCONTROL=ignoreboth:同时忽略以上两种。
    HISTCONTROL=erasedups:忽略所有历史命令中的重复命令。
    

    示例:

    # vim /etc/profile
    export HISTTIMEFORMAT="%F %T `whoami` "    这里插入了whoami用来显示命令的操作用户
    export HISTSIZE=100000
    export HISTFILESIZE=20000
    


    清空history

    当前session执行的命令,放置在缓存中,正常退出或关闭时,会把缓存信息写入 ~/.bash_history。
    当session直接被kill时,缓存中的命令不会写入 ~/.bash_history。

    1、清空历史命令文件

    # > ~/.bash_history
    

    2、清空当前缓存中的命令

    # history -c
    

    3、直接关闭终端即可。

    如果不想保留任何痕迹,退出时不要敲exit,这样exit会被保存。

  • 相关阅读:
    苹果和Google应该如何把二维码变成主流 | 36氪
    成绩换offer,中国版的Smarterer“一问一答”网站帮你把简历推荐给你想去的公司 | 36氪
    读过的一些书
    扫描QR码即可完成移动支付的LevelUp推出集合NFC、QR码等技术的移动支付终端,供商家免费使用 | 36氪
    “消息速递”团队推出“有声照片”,让照片同时拥有拍摄时的现场录音 | 36氪
    css3ps—ps直接生成css3 使用方法
    Google收购的Nik Software将会发力“服务器端图片处理”领域 | 36氪
    收藏本站
    让屏幕抖动一阵
    全中文日期显示
  • 原文地址:https://www.cnblogs.com/keithtt/p/7040549.html
Copyright © 2011-2022 走看看