英文:
how add a file in every dir and subdir
问题
我需要将文件放在每个目录和子目录中。
我在Mac上使用Bash和Brew。
我尝试了这个命令:
for dir in \`//Users/oscarristolfi/Downloads/roma/\* . -type d\` ; do cp index.html ; done
我已经尝试过了,但它只显示回显,结果如下:
/Users/oscarristolfi/Downloads/roma/copia.sh: line 7: //Users/oscarristolfi/Downloads/roma/cerco-amici: is a directory
我尝试添加一个目录变量,但没有效果:
for dir in \`//Users/oscarristolfi/Downloads/roma/\* . -type d\` ; do cp index.html $dir/index.html ; done
英文:
i need to put file in every dir and sub dir
i use bash on mac with brew
i tried this
for dir in \`//Users/oscarristolfi/Downloads/roma/\* . -type d\` ; do cp index.html ; done
i' have tried but it show only echo, result
/Users/oscarristolfi/Downloads/roma/copia.sh: line 7: //Users/oscarristolfi/Downloads/roma/cerco-amici: is a directory
i try tu add a dir variable but nothing
for dir in \`//Users/oscarristolfi/Downloads/roma/\* . -type d\` ; do cp index.html $dir/index.html ; done
答案1
得分: 1
我会使用find
而不是for
。
假设在运行find
的当前目录中存在index.html
:
find //Users/oscarristolfi/Downloads/roma/* -type d -exec cp index.html {} \;
为cp
添加选项:
-f
,如果你想强制覆盖目标目录中已存在的index.html
。-n
,如果你不想覆盖目标目录中已存在的index.html
。
我不熟悉MacOS和路径中的//Users
部分,但我假设它是某种链接到放置家目录的顶部的方式。
英文:
I would use find
instead of for
.
Given that index.html
exists in the current directory where you run find
from:
find //Users/oscarristolfi/Downloads/roma/* -type d -exec cp index.html {} \;
Add options to cp
:
-f
if you want to force overwriting an existingindex.html
in the target directory.-n
if you don't want to overwrite an existingindex.html
in the target directory.
<sup>I'm not familiar with MacOS and the //Users
part of the path, but I'm assuming it's some sort of link to the top of where the home directories are placed.</sup>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论