linux - 在终端 (Mac) 中的目录之间复制所有文件

标签 linux macos command-line terminal copy

当我尝试在 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/

相关文章:

c++ - 获取命令行() : unable to pass multiline arguments from batch-file (GCC-Compiler)

unix - mkdir 和 mkdir -p 有什么区别

python - linux守护进程无法运行python文件

linux - 使用 tar 将最新的 .gz 文件提取到另一个目录中

linux ami nginx sites_enabled 丢失

xcode - 如果构建中断,如何使XCode Run Script Build Phase运行?

ios - 无法运行 'Pod Setup'

c# - GTK# 使用绘图区

python - 在Python中使用scipy错误中的stats包?

linux - 命令行 : monitor log file and add data to database