曲径通幽论坛

 找回密码
 立即注册
搜索
查看: 2496|回复: 0
打印 上一主题 下一主题

几个快捷输入命令的方式

[复制链接]

4918

主题

5880

帖子

3万

积分

GROAD

曲径通幽,安觅芳踪。

Rank: 6Rank: 6

积分
34395
跳转到指定楼层
楼主
发表于 2013-3-5 10:57:03 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
1. TAB 补齐功能众所周知。

2. !n 和 !-n
其中,n 表示一个数字,这两个表达式是针对 history 命令而言的。先看一个 history 命令的输出:
$ history
    1  ls
    2  clear
    3  ifconfig -a
    4  ls
    5  ifconfig
    6  ping www.baidu.com
    7  ls
    8  cd Downloads/
    9  ls
   10  tar -xvzf mysql-5.6.10.tar.gz
   11  ls
   12  gcc -v
   13  ifconfig
   ... ... 部分省略 ... ...
   56  ifconfig -a
   57  vi my-new.cnf
   58  clear
   59  ls
   60  ls -l
   61  history
如果执行 !5  ,那么相当于敲入了命令 ifconfig ,即历史命令顺序第 5 条;相反的,如果执行 !-2,那么就是执行倒数的第 2 条(编号 60) 。

3. !! (双感叹号)
双感叹号是上一条输入命令,这个当然可以用向上方向键来获得。

4. !$
!$ 表示上一条命令中的最后一个参数。比如:
[beyes@centos mysql-5.6.10]$ echo "hello" "world"
hello world
[beyes@centos mysql-5.6.10]$ echo !$
echo "world"    #将 !$ 展开后的形式
world

5. !string
上面的 string 表示最近一条以它开头的命令,比如:
[beyes@centos mysql-5.6.10]$ who
beyes    pts/0        2013-03-04 09:58 (192.168.1.110)
beyes    pts/1        2013-03-05 09:59 (192.168.1.110)
[beyes@centos mysql-5.6.10]$ uname
Linux
[beyes@centos mysql-5.6.10]$ echo "hello"
hello
[beyes@centos mysql-5.6.10]$ !u
uname         #将 !u 展开后所得的命令
Linux

6. !?string?
其中 string 是最近执行的一条命令所包含的字符串,比如:
[beyes@centos mysql-5.6.10]$ echo "hello"
hello
[beyes@centos mysql-5.6.10]$ which ls
alias ls='ls --color=auto'
    /bin/ls
[beyes@centos mysql-5.6.10]$ ls
bin      data2  include         man         mysql_error.log  scripts    support-files
COPYING  data3  INSTALL-BINARY  my.cnf      mysql-test       share
data     docs   lib             my-new.cnf  README           sql-bench
[beyes@centos mysql-5.6.10]$ !?ch?
which ls                # 将 !?ch? 展开后所得的命令
alias ls='ls --color=auto'
    /bin/ls
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|曲径通幽 ( 琼ICP备11001422号-1|公安备案:46900502000207 )

GMT+8, 2025-5-4 18:21 , Processed in 0.076230 second(s), 23 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表