2016-03-01 68 views
-1

我是一個完整的bash /編碼業餘愛好者,迄今爲止我已經找到了研究此站點的所有答案(很棒)。 我有一個單獨的文件夾的每個文件,就像這樣:在不同文件夾中重命名具有相同名稱的文件,每個文件夾都有一個文件

/aaaa/aaaa.pdf 
/bbbb/bbbb.pdf 
/cccc/cccc.pdf 

但現在,我無法找到或弄清楚bash腳本給他們這樣的重命名:

/aaaa/file.pdf 
/bbbb/file.pdf 
/cccc/file.pdf 

我相信它將類似於在複雜性,從這個其他問題,這兩條線中的一個: Rename files in multiple directories to the name of the directory

for subdir in *; do mv $subdir/file.txt $subdir.txt; done; 

find . -type d -not -empty -exec echo mv \{\}/file.txt \{\}.txt \; 

要澄清,我的文件夾中運行包含的文件夾/ AAAA/BBBB/CCCC ......

非常感謝您

回答

2

你可以很容易地適應你引用了答案:

for subdir in *; do mv "$subdir/$subdir.pdf" "$subdir/file.pdf"; done 

我也添加了雙引號 - 當擴展變量時,您幾乎總是使用它們。

0
for file in $(find -mindepth 2 -type f); do mv $file $(dirname $file)/file.pdf; done 

十字路口與託比Speight,其答案更優雅反正。

相關問題