亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

  免費(fèi)注冊(cè) 查看新帖 |

Chinaunix

  平臺(tái) 論壇 博客 文庫(kù)
最近訪問(wèn)板塊 發(fā)新帖
查看: 2219 | 回復(fù): 6
打印 上一主題 下一主題

來(lái)一點(diǎn)兒不水的:輕松玩兒轉(zhuǎn) Bash History -- By Examples [復(fù)制鏈接]

論壇徽章:
0
跳轉(zhuǎn)到指定樓層
1 [收藏(0)] [報(bào)告]
發(fā)表于 2010-09-17 13:12 |只看該作者 |倒序?yàn)g覽
這個(gè)玩意兒看一下 man bash 其實(shí)就全有了。這里只是把它真正的用起來(lái)


Bash History Expansion 是Bash里面最常用的一個(gè)功能。這部分功能在Bash的手冊(cè)當(dāng)中分成了三個(gè)部分進(jìn)行描述。分別是 Event Designators,Word Designators 和 Modifiers 。 Event Designators 幫助我們找到曾經(jīng)用過(guò)的命令;Word Designators 可以引用命令當(dāng)中的不同部分;Modifiers 則提供了對(duì)引用內(nèi)容進(jìn)行修改的功能。靈活的使用 Bash History Expansion 可以在日常工作中節(jié)省大量的鍵盤輸入。

當(dāng)然在實(shí)際使用過(guò)程中,這三個(gè)部分都是綜合起來(lái)使用的。下面讓我們用一些實(shí)例來(lái)演示一下history expansion究竟有多么的playful。
Event Designators$The last argument. It's very useful in safety delete something.*All of the words but the zeroth.  This is a synonym for `1-$'.  It is not an error to use * if there is just one word in the event; the empty string is returned in that case.!$ 和 !* 是最常用的啦。沒(méi)有哪一個(gè)用法能夠比這個(gè)更常用。但是你有沒(méi)有想過(guò)用 !$ 和 !* 來(lái)增加 rm 的安全性呢?
  1. 3 : 2020 : 14:01:01 : ~/FreeMind.html_files
  2. dove@bash-4.1$ ls freemind2html.css *.png
  3. freemind2html.css  hide.png  ilink.png  image.png  leaf.png  show.png

  4. 3 : 2021 : 14:01:12 : ~/FreeMind.html_files
  5. dove@bash-4.1$ rm !*
  6. rm freemind2html.css *.png

  7. 3 : 2022 : 14:01:19 : ~/FreeMind.html_files
  8. dove@bash-4.1$ ls
  9. icons

  10. 3 : 2023 : 14:01:25 : ~/FreeMind.html_files
  11. dove@bash-4.1$
復(fù)制代碼


^string1^string2^
    Quick substitution.  Repeat the last command, replacingstring1withstring2.Equivalent to``!!:s/string1/string2/''(see Modifiers below).

s/old/new/
    Substitute new for the first occurrence of old in the event line. Any delimiter can be used in place of /. The final delimiter is optional if it is the last character of the event line. The delimiter may be quoted in old and new with a single backslash. If & appears in new, it is replaced by old. A single backslash will quote the &. If old is null, it is set to the last old substituted, or, if no previous history substitutions took place,the last string in a !?string[?] search.

替換是另一個(gè)很常用的功能。歷史總是驚人的相似,歷史命令也是這樣的。不同的部分通常只是一點(diǎn)點(diǎn)。把不同的替換掉,經(jīng)常就是你想要的命令了。

s/old/new/ 通常用在 ^old^new^ 夠不著了的時(shí)候。在進(jìn)行多個(gè)替換的時(shí)候還可以用 gs/old/new/ 或者 Gs/old/new/
  1. [root@tivg05 OSAgent]# bin/itmcmd agent -o tivg05 start m6
  2. bin/itmcmd agent -o tivg05 start m6
  3. Starting ... Manager Agent for  ...
  4. ... Manager Agent for started
  5. [root@tivg05 OSAgent]# bin/cinfo -r
  6. bin/cinfo -r

  7. *********** Tue Sep 14 11:40:22 EDT 2010 ******************
  8. User: root Groups: root bin daemon sys adm disk wheel mqm
  9. Host name : tivg05     Installer Lvl:06.22.02.00
  10. CandleHome: /opt/IBM/OSAgent
  11. ***********************************************************
  12. Host    Prod  PID    Owner  Start  ID      ..Status  
  13. tivg05  lz    1473   root   Sep02  None    ...running
  14. tivg05  m6    11749  root   11:39  tivg05  ...running
  15. [root@tivg05 OSAgent]# !-2:s/tivg05/hpi03/
  16. !-2:s/tivg05/hpi03/
  17. bin/itmcmd agent -o hpi03 start m6
  18. Starting... Manager Agent for  ...
  19. ... Manager Agent for started
  20. [root@tivg05 OSAgent]#
復(fù)制代碼

論壇徽章:
0
2 [報(bào)告]
發(fā)表于 2010-09-17 13:14 |只看該作者
!string
Refer to the most recent command starting with string.

!?string[?]
Refer to the most recent command containingstring.The trailing ? may be omitted ifstringis followed immediately by a newline.

這個(gè)是什么?其實(shí)呢想一想通常的 !2019,!-4:3-5 等等等等, !string 和 !?string? 的用處就是在你不愿意去數(shù)命令的時(shí)候,可以使用所包含的特征字符串來(lái)定位歷史命令。


  1. [root@tivg05 OSAgent]# bin/itmcmd agent -o tivg05 stop m6
  2. bin/itmcmd agent -o tivg05 stop m6
  3. Stopping ... Manager Agent for  ...
  4. Product ... Manager Agent for ... was stopped gracefully.
  5. Agent stopped...
  6. [root@tivg05 OSAgent]# bin/cinfo -r
  7. bin/cinfo -r
  8. *********** Tue Sep 14 12:30:21 EDT 2010 ******************
  9. User: root Groups: root bin daemon sys adm disk wheel mqm
  10. Host name : tivg05     Installer Lvl:06.22.02.00
  11. CandleHome: /opt/IBM/OSAgent
  12. ***********************************************************
  13. Host    Prod  PID    Owner  Start  ID     ..Status  
  14. tivg05  lz    1473   root   Sep02  None   ...running
  15. tivg05  m6    16210  root   11:41  hpi03  ...running
  16. [root@tivg05 OSAgent]# !?itmcmd?:s/tivg05/hpi03/
  17. !?itmcmd?:s/tivg05/hpi03/
  18. bin/itmcmd agent -o hpi03 stop m6
  19. Stopping ... Manager Agent for  ...
  20. Product ... Manager Agent for ... was stopped gracefully.
  21. Agent stopped...
  22. [root@tivg05 OSAgent]#
復(fù)制代碼

論壇徽章:
0
3 [報(bào)告]
發(fā)表于 2010-09-17 13:16 |只看該作者
Word Designators

x-

    Abbreviates x-$ like x*, but omits the last word.
x- 是一個(gè)比較有意思的東西。前面說(shuō)過(guò), !$ 是所有命令里面最常用的一個(gè),可是偏偏就有這么一種情況,需要變化的碰巧就是最后一個(gè)參數(shù),除此之外,其他全都不變。這個(gè)時(shí)候就是 x- 發(fā)揮作用的時(shí)候了。下面這個(gè)例子篇幅比較長(zhǎng),所以把他折疊起來(lái)了
  1. -bash-3.00# bin/itmcmd agent start ux
  2. Starting Monitoring Agent for UNIX OS ...
  3. Monitoring Agent for UNIX OS started
  4. -bash-3.00# !:0- hd
  5. bin/itmcmd agent start hd
  6. Starting Warehouse Proxy ...
  7. Warehouse Proxy started
  8. -bash-3.00# !:0- sy
  9. bin/itmcmd agent start sy
  10. Starting Summarization and Pruning Agent ...
  11. Summarization and Pruning Agent started
  12. -bash-3.00# ^start^stop
  13. bin/itmcmd agent stop sy
  14. Stopping Summarization and Pruning Agent ...
  15. Product Summarization and Pruning Agent was stopped gracefully.
  16. Agent stopped...
  17. -bash-3.00# !:0- hd
  18. bin/itmcmd agent stop hd
  19. Stopping Warehouse Proxy ...
  20. Product Warehouse Proxy was stopped gracefully.
  21. Agent stopped...
  22. -bash-3.00# !:0- ux
  23. bin/itmcmd agent stop ux
  24. Stopping Watchdog process...
  25. Watchdog process was stopped.
  26. Stopping Monitoring Agent for UNIX OS ...
  27. Product Monitoring Agent for UNIX OS was stopped gracefully.
  28. Agent stopped...
  29. -bash-3.00#
復(fù)制代碼

論壇徽章:
0
4 [報(bào)告]
發(fā)表于 2010-09-17 13:18 |只看該作者
!#

    The entire command line typed so far.

!# 玩兒起來(lái)就更加有意思了。 !# 引用的是當(dāng)前正在編寫的命令。被歷史命令引用,并不必須非得成為過(guò)去

  1. bash-3.00# bin/itmcmd server stop `hostname -s` && !#:0-1 start !#:3
  2. bin/itmcmd server stop `hostname -s` && bin/itmcmd server start `hostname -s`
  3. Stopping TEMS...
  4. It can take up to ten minutes.
  5. TEMS stopped...
  6. Starting TEMS...
  7. It can take up to ten minutes.
  8. TEMS started...
  9. bash-3.00#
復(fù)制代碼


M-#

Comment out your current input, put it into history list, then get back to the prompt

It's very useful when you have to issue another command in advance while typing this one


M-# 是一個(gè)值得大書特書的功能。想一想吧,每個(gè)人都遇到過(guò)輸入一條命令,輸?shù)揭话氲臅r(shí)候突然發(fā)現(xiàn)需要先去執(zhí)行另外一條命令,哎呀那個(gè)尷尬啊。其實(shí)這個(gè)時(shí)候只要同時(shí)按下鍵盤上的 Alt和#鍵(實(shí)際上就是Alt Shift 3),這個(gè)半拉子命令就被注釋掉了,并且還被加到了Bash的history list里面了。當(dāng)你執(zhí)行完“別的”命令,只需要叫回這條注釋,替換掉 # 號(hào)就可以執(zhí)行了。

  1. 2 : 2038 : 11:36:22 : ~
  2. dove@bash-4.1$ #mv ~/tivx06_m6_tivvm241_km6agent_4c733691-01.log.zip

  3. 2 : 2039 : 11:36:28 : ~
  4. dove@bash-4.1$ mkdir /tmp/ThinkPad-Emergency

  5. 2 : 2040 : 11:36:37 : ~
  6. dove@bash-4.1$ !-2:s/#// !$
  7. mv ~/tivx06_m6_tivvm241_km6agent_4c733691-01.log.zip /tmp/ThinkPad-Emergency

  8. 2 : 2041 : 11:36:47 : ~
  9. dove@bash-4.1$
復(fù)制代碼

論壇徽章:
0
5 [報(bào)告]
發(fā)表于 2010-09-17 13:20 |只看該作者
Modifiers
After the optional word designator, there may appear a sequence ofone or more of the following modifiers, each preceded by a `:'.

Modifiers 是一些更進(jìn)一步的編輯命令,通常和上面的命令結(jié)合使用。但是鑒于替換的規(guī)則不甚直觀,個(gè)人認(rèn)為實(shí)用價(jià)值比較有限。hRemove a trailing file name component, leaving only the head.tRemove all leading file name components, leaving the tail.rRemove a trailing suffix of the form .xxx, leaving thebasename.eRemove all but the trailing suffix.
  1. tivp5flp2.cn.ibm.com|/opt/IBM # KM6REM/bin/cinfo -r

  2. *********** Wed Sep 15 14:00:34 GMT+08:00 2010 ******************
  3. User: root Groups: system bin sys security cron audit lp mqm
  4. Host name : tivp5flp2    Installer Lvl:06.22.02.00
  5. CandleHome: /opt/IBM/KM6REM
  6. ***********************************************************
  7. Host       Prod  PID     Owner  Start  ID   ..Status  
  8. tivp5flp2  m6    794860  root   Aug    ma1  ...running
  9. tivp5flp2.cn.ibm.com|/opt/IBM # !:h/itmcmd agent -o ma1 stop m6
  10. KM6REM/bin/itmcmd agent -o ma1 stop m6
  11. Stopping ... Manager Agent for  ...
  12. Product ... Manager Agent for ... was stopped gracefully.
  13. Agent stopped...
  14. tivp5flp2.cn.ibm.com|/opt/IBM #
復(fù)制代碼

  1. 3 : 2007 : 12:51:05 : ~/org
  2. dove@bash-4.1$ ls /tmp/ThinkPad-Emergency/tivx06_m6_tivvm241_km6agent_4c733691-01.log.zip
  3. /tmp/ThinkPad-Emergency/tivx06_m6_tivvm241_km6agent_4c733691-01.log.zip

  4. 3 : 2008 : 12:51:16 : ~/org
  5. dove@bash-4.1$ echo !:$:r
  6. echo /tmp/ThinkPad-Emergency/tivx06_m6_tivvm241_km6agent_4c733691-01.log
  7. /tmp/ThinkPad-Emergency/tivx06_m6_tivvm241_km6agent_4c733691-01.log

  8. 3 : 2009 : 12:51:30 : ~/org
  9. dove@bash-4.1$ pwd
  10. /home/dove/org

  11. 3 : 2010 : 12:51:56 : ~/org
  12. dove@bash-4.1$ echo !-2:$:r
  13. echo /tmp/ThinkPad-Emergency/tivx06_m6_tivvm241_km6agent_4c733691-01
  14. /tmp/ThinkPad-Emergency/tivx06_m6_tivvm241_km6agent_4c733691-01

  15. 3 : 2011 : 12:52:12 : ~/org
  16. dove@bash-4.1$ echo !-4:$:r
  17. echo /tmp/ThinkPad-Emergency/tivx06_m6_tivvm241_km6agent_4c733691-01.log
  18. /tmp/ThinkPad-Emergency/tivx06_m6_tivvm241_km6agent_4c733691-01.log

  19. 3 : 2012 : 12:52:36 : ~/org
  20. dove@bash-4.1$
復(fù)制代碼

論壇徽章:
0
6 [報(bào)告]
發(fā)表于 2010-09-17 13:21 |只看該作者
  1. 0 : 2009 : 22:11:27 : ~
  2. dove@bash-4.1$ ls -a Shell/config/emacs.el/.abbrev_defs
  3. Shell/config/emacs.el/.abbrev_defs

  4. 0 : 2010 : 22:11:36 : ~
  5. dove@bash-4.1$ cat !$
  6. cat Shell/config/emacs.el/.abbrev_defs
  7. *** output flushed ***

  8. dove@bash-4.1$ diff !$ !#:t
  9. diff Shell/config/emacs.el/.abbrev_defs .abbrev_defs
  10. *** output flushed ***

  11. dove@bash-4.1$
復(fù)制代碼

論壇徽章:
16
IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-24 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2015-10-14 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-10-25 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-11-06 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-12-10 06:20:00平安夜徽章
日期:2015-12-26 00:06:302016猴年福章徽章
日期:2016-02-18 15:30:34IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-04-15 06:20:00IT運(yùn)維版塊每日發(fā)帖之星
日期:2016-05-21 06:20:00綜合交流區(qū)版塊每日發(fā)帖之星
日期:2016-08-16 06:20:002015七夕節(jié)徽章
日期:2015-08-21 11:06:17IT運(yùn)維版塊每日發(fā)帖之星
日期:2015-08-14 06:20:00
7 [報(bào)告]
發(fā)表于 2010-09-17 13:25 |只看該作者
路過(guò),友情幫頂
您需要登錄后才可以回帖 登錄 | 注冊(cè)

本版積分規(guī)則 發(fā)表回復(fù)

  

北京盛拓優(yōu)訊信息技術(shù)有限公司. 版權(quán)所有 京ICP備16024965號(hào)-6 北京市公安局海淀分局網(wǎng)監(jiān)中心備案編號(hào):11010802020122 niuxiaotong@pcpop.com 17352615567
未成年舉報(bào)專區(qū)
中國(guó)互聯(lián)網(wǎng)協(xié)會(huì)會(huì)員  聯(lián)系我們:huangweiwei@itpub.net
感謝所有關(guān)心和支持過(guò)ChinaUnix的朋友們 轉(zhuǎn)載本站內(nèi)容請(qǐng)注明原作者名及出處

清除 Cookies - ChinaUnix - Archiver - WAP - TOP