当我尝试在 Mac 上将文件从一个目录复制到另一个目录时,我使用以下命令:
sudo cp -r dir1/* dir2/
乍一看,好像还行。但是,它总是会跳过 .git、.gitignore 和 .htaccess 等文件。这是为什么?这些文件是否具有某种特权状态?
如果有帮助,dir1 是
的结果git clone
我在此之前运行的命令。
最佳答案
在命令中:
cp -r dir1/* dir2/
shell 展开 dir1/*
并将结果传递给 cp
。 *
模式不匹配前导.
,即它匹配通常可见的文件。您可以使用模式 dir1/.*
来匹配那些以 .
开头的条目,但是对于 cp
有更好的方法。来自 man cp
:
If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. If the source_file ends in a /, the contents of the directory are copied rather than the directory itself.
那么你所追求的是:
cp -r dir1/ dir2/
关于linux - 在终端 (Mac) 中的目录之间复制所有文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34031647/