linux - 递归复制和重命名

标签 linux bash shell find

我的结构如下:

./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

我需要将这些文件复制并重命名到与以下目录相同的目录:

./en-us/sitemap.html to ./en-us/psitemap.html
./en-es/sitemap.html to ./en-es/psitemap.html

我尝试了 findexec 的变体,但没有成功。

找到 . -type f -name "sitemap.html"-printf "cp %p %p\n"| sed 's/sitemap.html$/psitemap.html\1/g'

这里我尝试用psitemap.html 替换最后一个sitemap.html 失败了。

如何轻松复制和重命名这些文件?

最佳答案

您可以使用 -execdir 选项:

find . -type f -name "sitemap.html" -execdir echo mv {} psitemap.html \;

当对输出满意时,从上面的命令中删除 echo

关于linux - 递归复制和重命名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46111003/

相关文章:

linux - cifs mount 导致进程进入不间断 sleep

python - 将 python 代码的标准输出重定向到文件而不让 python 保持锁定

Bash 将 heredoc 输出重定向到/dev/null

linux - 使用管道时重新组合 bash 参数

linux - 计算输入文件中字符串的出现次数

java - 如何使用 JSch 在服务器上使用别名?

python - 无法使用python子进程popen挂载文件系统

bash - 如何关闭命名管道的作者?

shell - 如何在 OOZIE 的决策节点中动态获取文件名?

linux - 如何在shell脚本中扩展变量?