很多和正则表达式 re 是一致的;

1. 修改上次执行的命令

  • 删除多余部分;

    % grep fooo /var/log/auth.log
    % ^o
    % grep foo /var/log/auth.log
  • 替换(输错或少输):

    
    # 替换
    
    % cat myflie
    % ^li^il
    % cat myfile
    
    
    # 漏写
    
    % ansible vod -m command -a 'uptim'
    % ^im^ime
    % ansible vod -m command -a 'uptime'
  • 高级替换:

    % ansible nginx -m command -a 'which nginx'
    % !:gs/nginx/squid
    % ansible squid -m command -a 'which squid'
    % ^nginx^squid^:G # zsh

2. 善用命令行输入历史

  • 查询历史

    $ echo $HISTSIZE
    $ echo $HISTFILE
    
    $ history
    $ history | less
    $ history 5
  • !$:上一条命令的最后一位参数

    $ mkdir videos
    $ cd !$
  • !^:上一条命令的第一位参数

    $ ls /usr/share/doc /usr/share/man
    $ cd !^    
  • :t:截取路径的结尾

    $ wget http://nginx.org/download/nginx-1.4.7.tar.gz
    $ tar -zxvf !$:t
    tar -zxvf nginx-1.4.7.tar.gz
                    # 相当于取 basename
  • :r:截取文件名

    $ unzip filename.zip
    $ cd !$:r
    cd filename
  • :e:文件拓展名

references

posted on 2017-10-03 19:13  未雨愁眸  阅读(455)  评论(0编辑  收藏  举报