shell 如何在每个目录和子目录中添加文件

bsxbgnwa  于 2023-06-24  发布在  Shell
关注(0)|答案(1)|浏览(131)

我需要把文件在每个目录和子目录
我在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
h9a6wy2h

h9a6wy2h1#

我会使用find而不是for。假设index.html存在于运行find的当前目录中:

find //Users/oscarristolfi/Downloads/roma/* -type d -exec cp index.html {} \;

cp添加选项:

  • -f,如果您想强制覆盖目标目录中现有的index.html
  • -n,如果不想覆盖目标目录中现有的index.html

我不熟悉MacOS和路径的//Users部分,但我假设它是指向主目录顶部的某种链接。

相关问题