Chapter 18 Working Faster by Typing Less

1.1 Moving Quickly Among Arbitrary Directories

Use the pushd and popd built-in commands to manage a stack of directory locations, and to switch between them easily.

[root@MaxwellDBA ~]#  mkdir /var/log/cups
[root@MaxwellDBA ~]# pwd
/root
[root@MaxwellDBA ~]# cd /tmp/tank
[root@MaxwellDBA tank]# pwd
/tmp/tank
[root@MaxwellDBA tank]# pushd /var/log/cups
/var/log/cups /tmp/tank
[root@MaxwellDBA cups]# pwd
/var/log/cups
[root@MaxwellDBA cups]# touch access_log error_log page_log
[root@MaxwellDBA cups]# ls
access_log  error_log  page_log
[root@MaxwellDBA cups]# popd
/tmp/tank
[root@MaxwellDBA tank]# ls
[root@MaxwellDBA tank]# ls
[root@MaxwellDBA tank]# touch empty full
[root@MaxwellDBA tank]# ls
empty  full
[root@MaxwellDBA tank]# pushd /var/log/cups
/var/log/cups /tmp/tank
[root@MaxwellDBA cups]# pushd
/tmp/tank /var/log/cups
[root@MaxwellDBA tank]# pushd
/var/log/cups /tmp/tank
[root@MaxwellDBA cups]# pushd
/tmp/tank /var/log/cups
[root@MaxwellDBA tank]# dirs
/tmp/tank /var/log/cups
[root@MaxwellDBA tank]# 

1.2 Repeating the Last Command

The other (more modern) solution involves using the arrow keys. Typing the uparrow key will scroll back through the previous commands that you have issued. When you find the one you want, just press the Enter key and that command will be run (again).

[maxwell@MaxwellDBA Day0801]$ /usr/bin/somewhere/someprog -g -H -yknot -w /tmp/soforthandsoon
-bash: /usr/bin/somewhere/someprog: No such file or directory
[maxwell@MaxwellDBA Day0801]$ !!
/usr/bin/somewhere/someprog -g -H -yknot -w /tmp/soforthandsoon
-bash: /usr/bin/somewhere/someprog: No such file or directory
[maxwell@MaxwellDBA Day0801]$

1.3 Running Almost the Same Command\

If you’re going to use this feature, just be careful with your substitutions. If you had tried to change the -g option by typing !!:s/g/h/ you would have ended up changing Substituting Across Word Boundaries | 457 the first letter g, which is at the end of the command name, and you would be trying to run /usr/bin/somewhere/someproh.

[maxwell@MaxwellDBA Day0801]$ /usr/bin/somewhere/someprog -g -H -yknot -w /tmp/soforthandsoon
-bash: /usr/bin/somewhere/someprog: No such file or directory
[maxwell@MaxwellDBA Day0801]$ !!:s/H/A/
/usr/bin/somewhere/someprog -g -A -yknot -w /tmp/soforthandsoon
-bash: /usr/bin/somewhere/someprog: No such file or directory
[maxwell@MaxwellDBA Day0801]$ 

1.4 Substituting Across Word Boundaries

Use the caret (^) substitution mechanism:

[maxwell@MaxwellDBA Day0801]$ /usr/bin/somewhere/someprog -g -A -yknot -w /tmp/soforthandsoon
-bash: /usr/bin/somewhere/someprog: No such file or directory
[maxwell@MaxwellDBA Day0801]$ ^-g -A^-gB^
/usr/bin/somewhere/someprog -gB -yknot -w /tmp/soforthandsoon
-bash: /usr/bin/somewhere/someprog: No such file or directory
[maxwell@MaxwellDBA Day0801]$ 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值