递归复制文件夹,排除部分文件夹 [英] 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
注意使用 source
和 source/
是不同的.尾部斜杠表示将文件夹source
的内容复制到destination
中.没有斜杠,表示将文件夹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
.
或者,如果您有很多目录(或文件)要排除,您可以使用 --exclude-from=FILE
,其中 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.
--exclude
也可以包含通配符,比如 --exclude=*/.svn*
--exclude
may also contain wildcards, such as --exclude=*/.svn*
这篇关于递归复制文件夹,排除部分文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!