简体   繁体   English

复制除特定文件之外的所有内容

[英]Copy everything except specific files

How can I copy everything (files and directories(even if they are empty)) from one directory to another, except files ".php", and files with name "config.yml".如何将所有内容(文件和目录(即使它们是空的))从一个目录复制到另一个目录,但文件“.php”和名称为“config.yml”的文件除外。 I need to do this with single command.我需要用一个命令来做到这一点。 I have tried this one我试过这个

find./ -type f.查找。/ -type f。 ( -name "*.php" -o -name "config.yml" ) -exec cp --parents -r -t /my/directory/ "{}" + ( -name "*.php" -o -name "config.yml" ) -exec cp --parents -r -t /my/directory/ "{}" +

It works but if the directory have only files ".php", command will skip the directory and do not copy the empty one, but I need the directory even if it will be empty.它可以工作,但如果目录只有文件“.php”,命令将跳过目录并且不复制空目录,但即使目录为空,我也需要该目录。

Sorry, I haven't enough reputation to put a comment, because I would like to ask you if the use of "find" is a requisite.抱歉,我没有足够的声誉来发表评论,因为我想问你是否需要使用“find”。

If is not, you can do it easily with the rsync command:如果不是,您可以使用 rsync 命令轻松完成:

rsync -av --exclude=config.yml --exclude="*php" ORIGINFOLDER/ DESTFOLDER rsync -av --exclude=config.yml --exclude="*php" ORIGINFOLDER/DESTFOLDER

Just change ORIGINFOLDER and DESTFOLDER for your folders name, and take a look at the man to see the meaning of the options.只需更改文件夹名称的 ORIGINFOLDER 和 DESTFOLDER,然后查看 man 以了解选项的含义。

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

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