2014-11-03 119 views
0

比方說,有目錄和文件這樣的:爲什麼沒有這個殼工作

  • ./app/cores/a/conf/props.conf.indexer
  • ./app/cores/a/conf/props.conf.searcher
  • ./app/cores/b/conf/props.conf.indexer
  • ./app/cores/b/conf/props.conf.searcher
  • ./app/cores/c/conf/props.conf.indexer
  • ./app/cores/c/conf/props.conf.searcher

在我將應用程序目錄部署到索引節點後,我想將app/cores/{core}/conf/props.conf.indexer更改爲app/cores/{core}/conf/props.conf

這裏是我做過什麼:

find ./app/cores/*/conf -name "props.conf.indexer" -exec echo $(cd $(dirname {}) && mv props.conf.indexer props.conf && ls -d props.conf) \; 

,但是,它已經返回(props.conf.indexer存在):

mv: rename props.conf.indexer to props.conf: No such file or directory 

我的問題是,它是否是不可能使用{}佔位符$()表達或不。

+2

的'$()'部分得到由殼*之前*'find'執行。 – Biffen 2014-11-03 10:44:19

+0

謝謝,這就是我想知道的 – 2014-11-03 13:38:02

回答

1

$()會前find進行評估(如@Biffen指出的)你不需要echo東西是已經文本等等,應有盡有。那麼ls -d是什麼?當然props.conf不是一個目錄?

這應該做你想要什麼:

for file in app/cores/*/conf/props.conf.indexer 
do 
    mv "$file" "${file%.indexer}" 
done 
+0

他們不是目錄。我想用一行shell命令來處理它。 – 2014-11-03 13:40:13

+1

@TaejunJang:單行命令shell命令被高估(恕我直言),但你可以將它轉換爲一行:'for app/cores/*/conf/props.conf.indexer中的文件;做mv「$ file」「$ {file%.indexer}」; (注意';'字符,我已經把這些行加在一起了,'do'後面的cmd不必用';'來分隔)。祝你們好運。 – shellter 2014-11-03 15:16:47

相關問題