Reputation: 55022
I have a structure as follows:
./tr-it/sitemap.html
./en-nl/sitemap.html
./fr-ca/sitemap.html
./it-it/sitemap.html
./fr-fr/sitemap.html
./tr-ir/sitemap.html
./en-it/sitemap.html
./en-us/sitemap.html
./en-kr/sitemap.html
./tr-ru/sitemap.html
./en-fr/sitemap.html
./en-int/sitemap.html
./en-tr/sitemap.html
./tr-us/sitemap.html
./tr-nl/sitemap.html
./en-ar/sitemap.html
./en-ir/sitemap.html
./en-se/sitemap.html
./es-us/sitemap.html
./en-ru/sitemap.html
./en-es/sitemap.html
./tr-es/sitemap.html
./es-ar/sitemap.html
./en-ca/sitemap.html
./pt-pt/sitemap.html
./tr-tr/sitemap.html
I need to copy and rename these files to the same directory as:
./en-us/sitemap.html to ./en-us/psitemap.html
./en-es/sitemap.html to ./en-es/psitemap.html
I tried variations of find
and exec
but no luck.
find . -type f -name "sitemap.html" -printf "cp %p %p \n" | sed 's/sitemap.html$/psitemap.html\1/g'
Here I tried to replace the last sitemap.html with psitemap.html and failed.
How can i copy and rename these files easily?
Upvotes: 1
Views: 59
Reputation: 784958
You can use -execdir
option:
find . -type f -name "sitemap.html" -execdir echo mv {} psitemap.html \;
When satisfied with output, remove echo
from above command.
Upvotes: 4
Reputation: 241768
Use parameter expansion - substitution:
for file in ./*/sitemap.html ; do cp "$file" "${file/sitemap/psitemap}" ; done
Upvotes: 4