终端:如何将文件粘贴到目录中的所有子文件夹?
Terminal: how can I paste a file to all the subfolders within a directory?
基本上,我创建了一个包含以下内容的 .gitignore
文件(忽略所有 class 文件但不忽略 .gitignore
文件):
# Ignore files below
*.class
# but not these files
!.gitignore
我想将其传播到目录中的所有子文件夹甚至子文件夹。
我知道我可以通过手动复制和粘贴以天真的方式完成。
但是有没有更好的方法在终端中使用一些命令来做到这一点?
find . -type d -print | xargs -L 1 cp .gitignore
find 命令打印出 下所有目录的名称。并包括 .
带有 -L 1 参数的 xargs 命令对找到的每个目录执行 cp .gitignore <dir>
。
您会看到有关未将 .gitignore 复制到当前目录中自身的错误。
您不必 ("propagate this to all sub-folders or even sub-sub-folders within the directory"):
.gitignore
规则将应用于所有子文件夹,除非另一个 .gitignore
规则(在其中一个子文件夹中)覆盖该规则。
参见Pro Git book gitignore
section:
Patterns read from a .gitignore
file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.
基本上,我创建了一个包含以下内容的 .gitignore
文件(忽略所有 class 文件但不忽略 .gitignore
文件):
# Ignore files below
*.class
# but not these files
!.gitignore
我想将其传播到目录中的所有子文件夹甚至子文件夹。
我知道我可以通过手动复制和粘贴以天真的方式完成。
但是有没有更好的方法在终端中使用一些命令来做到这一点?
find . -type d -print | xargs -L 1 cp .gitignore
find 命令打印出 下所有目录的名称。并包括 .
带有 -L 1 参数的 xargs 命令对找到的每个目录执行 cp .gitignore <dir>
。
您会看到有关未将 .gitignore 复制到当前目录中自身的错误。
您不必 ("propagate this to all sub-folders or even sub-sub-folders within the directory"):
.gitignore
规则将应用于所有子文件夹,除非另一个 .gitignore
规则(在其中一个子文件夹中)覆盖该规则。
参见Pro Git book gitignore
section:
Patterns read from a
.gitignore
file in the same directory as the path, or in any parent directory, with patterns in the higher level files (up to the toplevel of the work tree) being overridden by those in lower level files down to the directory containing the file.