zoukankan      html  css  js  c++  java
  • 命令

    原文地址:http://www.debugfs.com/?p=64

    • 给history命令添加时间戳

    通常,我们执行history命令时,就像这样:

     1000  screen -S ac
     1001  ls
     1002  history

    但我们可以通过修改HISTTIMEFORMAT来给history命令的显示增加时间戳,这有时候也是审计所需要的

    [haoli@proudgather Desktop]$ export HISTTIMEFORMAT='%F %T '
    [haoli@proudgather ~]$ history | tail -4
     1010  2010-06-12 08:51:41 ls
     1011  2010-06-12 08:51:48 cd ~/Desktop/
     1012  2010-06-12 08:52:00 cd ..
     1013  2010-06-12 08:52:05 history | tail -4

    • 使用Ctrl + r 来搜索history中的命令

    也许这个将成为你最经常使用的一个,比如你进入了一个很深的目录,但你不想再输入一遍,而且使用向上箭头一直翻将会很麻烦,这时就可以使用Ctrl+r来帮助你完成。

    [haoli@proudgather ~]$ #输入ctrl+r
    (reverse-i-search)`wordpress': cd wwwroot/wordpress/wp-admin/maint/

    如果显示的就是你想输入的命令,按回车就可以执行它了,如果想修改一下,按左右箭头即可。

    • 重复执行前一条命令的4中方法

    1.大家都知道的“上箭头”
    2.命令行中输入”!!”
    3.命令行中舒服”!-1″
    4.ctrl+p

    [haoli@proudgather maint]$ echo a
    a
    [haoli@proudgather maint]$ !!
    echo a
    a
    [haoli@proudgather maint]$ !-1
    echo a
    a

    • 执行历史中的某条命令

    执行history时,会在第一列显示序号,我们想执行哪个,只要!序号

    [haoli@proudgather ~]$ history | tail -4
     1038  2010-06-12 09:24:49 ls
     1039  2010-06-12 09:24:50 cd
     1040  2010-06-12 09:24:54 echo a
     1041  2010-06-12 09:25:01 history | tail -4
    [haoli@proudgather ~]$ !1040
    echo a
    a
    [haoli@proudgather ~]$

    • 利用字符串匹配执行最近的命令

    这个啥也不说了,直接来代码

    [haoli@proudgather test]$ echo a
    a
    [haoli@proudgather test]$ echo b
    b
    [haoli@proudgather test]$ !ec
    echo b
    b

    • 控制history命令输出的条数

    通过两个变量来完成,HISTSIZE控制history显示的条数,HISTFILESIZE控制.bash_history中保持的条数

    • 修改history历史文件的保存位置

    对,还是改变量,HISTFILE

    • 命令去重

    如果我们重复输入了很多命令,那么这些都会显示在history的输出中,如果我们不想看见这些,那么export HISTCONTROL=ignoredups就ok了,当然这对已经输入的命令就不起作用了,只对后面的重复输入有效

    • 屏蔽某些命令

    我们可以使用export HISTCONTROL=ignorespace使history忽略开头为空格的命令,这样就可以隐藏自己的操作了

    [haoli@proudgather ~]$ export HISTCONTROL=ignorespace
    [haoli@proudgather ~]$  cd ~/.ssh
    [haoli@proudgather .ssh]$ history | tail -2
       19  export HISTCONTROL=ignorespace
       20  history | tail -2

    • 清除history历史

    history -c

  • 相关阅读:
    Vitrualbox虚拟机网络设置
    挂接命令(mount) 【转】
    ubuntu Error mounting /dev/sda6 at /media/xxx...
    mysql命令[转]
    fopen参数
    fprintf&prinft&sprintf
    UNIX 网络编程知识,函数积累
    vim 括号自动补全
    CDbConnection failed to open the DB connection
    [Android_蓝牙]Android4.0蓝牙使能的详细解析
  • 原文地址:https://www.cnblogs.com/wangkangluo1/p/2186017.html
Copyright © 2011-2022 走看看