简体   繁体   English

在bash中,cp是否在使用通配符时复制点文件? 我应该使用哪个选项

[英]In bash, cp does copy dot files while using wildcard? Which option should I use

When I use cp -r source dest, the dot files as in .gitIgnore or any .xyz are ignored. 当我使用cp -r source dest时,.gitIgnore或任何.xyz中的点文件将被忽略。 When I use cp -r source/.xyz dest, then they are copied. 当我使用cp -r source / .xyz dest时,它们将被复制。 Which option with cp can copy all the files including the dot files while using the wildcard *? 使用通配符*时,使用cp的哪个选项可以复制包括点文件在内的所有文件?

You can use the wildcard like cp -r .[^.]* 您可以使用cp -r之类的通配符。[^。] *

Thats because your bash is built to ignore the hidden files and cp command just don't get the hidden arguments. 那是因为您的bash旨在忽略隐藏文件,而cp命令只是不获取隐藏参数。 Thats how its supposed to work .. :) 多数民众赞成在它应该如何工作.. :)

While using a wildcard * , you can try the command cp source/*.* destination/ to copy all the hidden files too. 使用通配符* ,您也可以尝试使用cp source/*.* destination/命令来复制所有隐藏文件。

If you want to include unhidden directories in the cp command you can try the below command 如果要在cp命令中包括未隐藏的目录,可以尝试以下命令

cp -r source/. destination/

Note the . 注意. at the end of source. 在源代码末尾。 That includes all the files and directories in the source including hidden ones. 这包括源中的所有文件和目录,包括隐藏的文件和目录。

Or 要么

cp -r source/{.,}* destination/

x{.,}y is converted to xy and xy . x{.,}y转换为xyxy In your case it will be source/.* and source/* 在您的情况下,它将是source/.*source/*

As for me the most universal way: 至于我最普遍的方式:

cp -a /source/. /destination/

Or if you are inside of a source folder: 或者,如果您位于源文件夹中:

cp -a . /destination/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM