2011-09-01 112 views
0

我試圖創建下面的命令它循環轉換所有文件的權限在當前目錄爲644別名,而另一個將所有的目錄轉換爲755把find命令的別名

alias fixpermissions='cd ~/public_html/wp-content/themes/presstheme; find . -type f -exec chmod 644 {} \; find . -type d -exec chmod 755 {} \; cd' 

然而,當我運行此我得到:

find: paths must precede expression 

這些find命令通過自己在外殼做工精細。爲了將命令作爲別名運行,你有什麼特別的事嗎?

謝謝!

回答

2

你需要額外的分號來分隔兩找到他們周圍的命令:

alias fixpermissions='cd ~/public_html/wp-content/themes/presstheme; find . -type f -exec chmod 644 {} \; ; find . -type d -exec chmod 755 {} \; ; cd' 

你可以使用一個子shell中受益;那麼你並不需要最後cd(這需要你回家,不回你原來的地方):

alias fixpermissions='(cd ~/public_html/wp-content/themes/presstheme; find . -type f -exec chmod 644 {} \; ; find . -type d -exec chmod 755 {} \;)' 

而且,自從我開始用貝殼之前有別名,我會製作成此在我的bin目錄清晰的腳本:

cd ~/public_html/wp-content/themes/presstheme 
find . -type f -exec chmod 644 {} \; 
find . -type d -exec chmod 755 {} \; 

,也許我將其參數化,太:

cd ${1:-"~/public_html/wp-content/themes/presstheme"} 
find . -type f -exec chmod 644 {} \; 
find . -type d -exec chmod 755 {} \; 

然後,我可以,如果我想指定不同的目錄,但它會defaul t到'正常'之一。

4

你需要幾個半冒號分隔的實際find命令(而不是終止它們),即

alias fixpermissions='cd ~/public_html/wp-content/themes/presstheme; find . -type f -exec chmod 644 {} \; ; find . -type d -exec chmod 755 {} \; ; cd' 

您可以防彈您的別名只搜索你的presstheme目錄(如果它存在允許通過cd後使每個指令有條件地執行移動你的別名到其他機器)的情況下,即

alias fixpermissions='cd ~/public_html/wp-content/themes/presstheme && find . -type f -exec chmod 644 {} \; && find . -type d -exec chmod 755 {} \; && cd' 

我希望這有助於。

+0

謝謝,這個作品! – jrue

1

您錯過了結束第一個查找命令的分號。您只提供了結束chmod命令的分號。

alias fixpermissions='find ~/public_html/wp-content/themes/presstheme -type f -exec chmod 644 {} \; ; find ~/public_html/wp-content/themes/presstheme -type d -exec chmod 755 {} \; cd'