Isso funciona para mim:
rename -vn 's/([^\/]+)\/index/$1\/$1/' folder*/*.html
Impressões:
folder1/index.html renamed as folder1/folder1.html
folder2/index.html renamed as folder2/folder2.html
folder3/index.html renamed as folder3/folder3.html
folder4/index.html renamed as folder4/folder4.html
folder5/index.html renamed as folder5/folder5.html
Outra solução com sed
:
ls -1 folder*/*.html | sed 's/\([^\/]\+\)\/index.html/mv "mv "folder1/index.html" "folder1/folder1.html"
mv "folder2/index.html" "folder2/folder2.html"
mv "folder3/index.html" "folder3/folder3.html"
mv "folder4/index.html" "folder4/folder4.html"
mv "folder5/index.html" "folder5/folder5.html"
" "\/.html"/'
Impressões:
ls -1 folder*/*.html | sed 's/\([^\/]\+\)\/index.html/mv "rename -vn 's/([^\/]+)\/index/$1\/$1/' folder*/*.html
" "\/.html"/' | bash
Se isso imprimir os comandos corretos, canalize-o para bash
. Mas primeiro certifique-se de que os comandos impressos funcionem antes de executá-lo:
folder1/index.html renamed as folder1/folder1.html
folder2/index.html renamed as folder2/folder2.html
folder3/index.html renamed as folder3/folder3.html
folder4/index.html renamed as folder4/folder4.html
folder5/index.html renamed as folder5/folder5.html