2014-11-03 132 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