在子目录中重命名文件时遇到问题(有条件)[shell脚本]

时间:2016-02-15 11:24:38

标签: shell file-rename

我没有成功写出正确的代码!

我的目录是这样的

*[href]

黄色目录中有大约999个阴影文件夹,每个文件夹都包含     2或3个文件(/Users/dave/yellow/shade001/light /Users/dave/yellow/shade001/dark1 /Users/dave/yellow/shade001/dark2 ... /Users/dave/yellow/shade999/light /Users/dave/yellow/shade999/dark1 /Users/dave/yellow/shade999/dark2 始终存在,light始终存在,dark1某个时间存在)。我想重命名dark2light并删除dark1,以便:{/ p>

dark2

这就是我所做的:

light.txt renamed to lgt.txt dark1.txt renamed to dk1.txt dark2 (whenever found) should be deleted

1 个答案:

答案 0 :(得分:1)

在Bash或类似的shell中:

find shade* -name light.txt | while read NAME; do mv $NAME `dirname $NAME`/lgt.txt; done

类似于dark1dark2(在后一种情况下,rm而不是mv)。

相关问题