為您推薦:
2014-10-21 22:40網友采納
bash只有擴展,沒正則這樣操作的。
摘錄一點,你看看
奇特的用法
當場替換文件名的
$ mv thisisareallylongfilename{,.txt}
這個命令將把“thisisareallylongfilename”這個文件改名成“thisisareallylongfilename.txt”,這樣就可以不用把這個長文件名打兩遍了,雖然在shell中有tab按鍵可以自動填補文件名,這個小技巧看來不是很有用,但在shell腳本中還是非常有用的。
$ mv foo.{jpeg,jpg}
這個命令將把foo.jpeg改名為foo.jpg。
mv xxx{yyy,www}zzz.tt
擴展
其實,類似數組的擴展。
● echo /etc/init/avahi-{daemon,lol,what}.conf
/etc/init/avahi-daemon.conf /etc/init/avahi-lol.conf /etc/init/avahi-what.conf
● for i in a{2,{1..3},5}; do echo $i; done
a2
a1
a2
a3
a5