注:該文章是從http://talk.linuxtoy.org/using-cli/ 這轉載過來的css
cat myflie
用下面的命令進行修正html
^li^il
輸入上面的命令後,會自動出現下面的命令node
cat myfile
ansible vod -m command -a 'uptim'
當輸錯後,使用下面的命令行來進行處理糾正錯誤linux
^im^ime
使用上面這個命令後,會自動的出現下面的內容nginx
ansible vod -m command -a 'uptime'
ansible nginx -m command -a 'which nginx'
須要把nginx所有替換成squid,使用命令以下vim
!:gs/nginx/squid
輸完命令後,會自動變更以下segmentfault
ansible squid -m command -a 'which squid'
若是你使用的是zsh的話,須要使用以下命令全局替換bash
^nginx^squid^:G # zsh
echo $HISTSIZE 1000
echo $HISTFILE /home/xiaodong/.zhistory
echo $HISTFILESIZE # bash 1000 echo $SAVEHIST # zsh 1000
注:上面兩個命令我在個人MAC中輸出的結果爲空,個人MAC的環境是zsh,各位在測試的時候須要注意less
% history % history | less 1 hist 2 ./code/gs/update_system.pl -n 3 emerge -C chromium 4 emerge @preserved-rebuild 5* df -h ...... % history 5 % history | grep string
% (reverse-i-search)`h': history 5
% history 5 [Ctrl + p]
% [Ctrl + n]
% !! % sudo !! % apt-get install figlet E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied) E: Unable to lock the administration directory (/var/lib/dpkg/), are you root? % sudo !! sudo apt-get install figlet
% !his history
% !?is echo $histchars
注:這個若是是多個命令包含is的話,那就是執行最新的一個,感受這個有點雞肋ide
% !10 vim lib/TunePage.pm
注:表示執行歷史命令中的第十個命令,這須要你對歷史命令的執行次數很熟悉,能夠針對歷史命令標號的方式進行標記
% !-2 htop % !-1 == !! Tip: 給命令提示符中增長曆史命令編號 % export PS1='!\! \u@\h:\w\$ ' !998 xiaodong@codetoy:~$
% cp filename filename.old % cp filename !#:1.old
注:cp filename !#:1.old
這個是一個完整的命令,其執行後,出現的結果就是顯示命令cp filename filename.old
注:這個確實尚未明白什麼意思
% mkdir videos % cd !$ % [Alt + .] #這個不知道幹嗎的
% ls /usr/share/doc /usr/share/man % cd !^ #等價於cd /usr/share/doc % [Ctrl + Alt + y] #未知
% touch foo.txt bar.txt baz.txt % vim !:2 vim bar.txt
% touch foo.txt bar.txt baz.txt % vim !:1-2 vim foo.txt bar.txt
% cat /etc/resolv.conf /etc/hosts /etc/hostname % vim !:2* vim /etc/hosts /etc/hostname
% ls code src % cp -r !*
% !an:$ % !10:2-4 % !{an}2
% ls /usr/share/fonts/truetype % cd !$:h cd /usr/share/fonts
注:這個至關於dirname
% 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
% echo abc.jpg % echo !$:e echo .jpg # bash .jpg echo jpg # zsh jpg
% echo * README.md css img index.html js % !:p echo *
% echo this that % !:s/is/e echo the that
注:慣用法: ^is^e
* 利用 :g 作全局操做
% echo abcd abef % !:gs/ab/cd echo cdcd cdef cdcd cdef
% echo $histchars % echo !$:u echo $HISTCHARS
% echo !$:l echo $histchars
h|t
r|e
p
s
g
u|l
% ls /usr/share/fonts/opentype % echo !$:t:u echo OPENTYPE
% cp file.c file.c.bak % cp file.c{,.bak} % echo cp file.c{,.bak} % vim {a,b,c}file.c vim afile.c bfile.c cfile.c % vim [abc]file.c # ? % vim {a..c}file.c # bash % setopt braceccl # zsh % vim {a-c}file.c # zsh
% wget http://linuxtoy.org/img/{1..5}.jpg 1.jpg 2.jpg 3.jpg 4.jpg 5.jpg % touch {01..5}.txt 01.txt 02.txt 03.txt 04.txt 05.txt % touch {1..10..2}.txt 1.txt 3.txt 5.txt 7.txt 9.txt % echo {1..10..-2} # zsh 9 7 5 3 1 % echo {9..1..2} # bash 9 7 5 3 1
% mkdir -p 2014/{01..12}/{baby,photo} % echo {{A..Z},{a..z},{0..9}}
% grep -l error *.pm # (1) TunePage.pm % vim TunePage.pm # (2) % vim `grep -l error *.pm` % vim $(grep -l error *.pm) 嵌套時,$() 可讀性更清晰,而 `` 則較差 % vim $(grep -l failed $(date +'%Y%m%d').log) % vim `grep -l failed \`date +'%Y%m%d'\`.log`
Type less, accomplish more (少打多作)
DRY, don't repeat yourself (不要重複你本身)
Care about your tool (關心你的工具)
bash: man history
zsh: man zshexpn
Bash Reference Manual:
https://www.gnu.org/software/bash/manual/html_node/index.html
A User's Guide to ZSH:
http://zsh.sourceforge.net/Guide/zshguide.html
Book: Unix Power Tools