gpt4 book ai didi

linux - 递归复制和重命名

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:17:37 25 4
gpt4 key购买 nike

我的结构如下:

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com