复制文件夹递归,排除某些文件夹 [英] Copy folder recursively, excluding some folders
问题描述
我试图写一个简单的bash脚本,将复制包括隐藏文件和文件夹到另一个文件夹的文件夹的全部内容,但我想排除某些特定的文件夹。我怎么能做到这一点?
I am trying to write a simple bash script that will copy the entire contents of a folder including hidden files and folders into another folder, but I want to exclude certain specific folders. How could I achieve this?
推荐答案
使用rsync的:
rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination
请注意,使用源
和源/
是不同的。尾随斜线意味着到文件夹源
中的内容复制到目标
。如果没有斜杠,这意味着复制文件夹源
到目标
。
Note that using source
and source/
are different. A trailing slash means to copy the contents of the folder source
into destination
. Without the trailing slash, it means copy the folder source
into destination
.
另外,如果你有很多的目录(或文件)的排除,你可以使用 - 排除 - 从=文件
,其中 FILE
是包含文件或目录排除一个文件的名称。
Alternatively, if you have lots of directories (or files) to exclude, you can use --exclude-from=FILE
, where FILE
is the name of a file containing files or directories to exclude.
- 排除
也可以包含通配符,如 - 排除= * / SVN *
--exclude
may also contain wildcards, such as --exclude=*/.svn*
这篇关于复制文件夹递归,排除某些文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!