Kal*_*son 320
使用rsync:
rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination
Run Code Online (Sandbox Code Playgroud)
请注意,使用source和source/不同.尾部斜杠表示将文件夹的内容复制source到destination.如果没有尾部斜杠,则表示将文件夹复制source到destination.
或者,如果要排除许多目录(或文件),则可以使用--exclude-from=FILE,FILE包含要排除的文件或目录的文件的名称.
--exclude 也可能包含通配符,例如 --exclude=*/.svn*
Kyl*_*utt 37
使用焦油和管道.
cd /source_directory
tar cf - --exclude=dir_to_exclude . | (cd /destination && tar xvf - )
Run Code Online (Sandbox Code Playgroud)
你甚至可以在ssh中使用这种技术.
您可以使用find该-prune选项.
一个例子来自man find:
cd /source-dir
find . -name .snapshot -prune -o \( \! -name *~ -print0 \)|
cpio -pmd0 /dest-dir
This command copies the contents of /source-dir to /dest-dir, but omits
files and directories named .snapshot (and anything in them). It also
omits files or directories whose name ends in ~, but not their con?
tents. The construct -prune -o \( ... -print0 \) is quite common. The
idea here is that the expression before -prune matches things which are
to be pruned. However, the -prune action itself returns true, so the
following -o ensures that the right hand side is evaluated only for
those directories which didn't get pruned (the contents of the pruned
directories are not even visited, so their contents are irrelevant).
The expression on the right hand side of the -o is in parentheses only
for clarity. It emphasises that the -print0 action takes place only
for things that didn't have -prune applied to them. Because the
default `and' condition between tests binds more tightly than -o, this
is the default anyway, but the parentheses help to show what is going
on.
跑步:
\nrsync -av --exclude=\'path1/in/source\' --exclude=\'path2/in/source\' [source]/ [destination]\nRun Code Online (Sandbox Code Playgroud)\n-avr将创建一个名为 的新目录[destination]。source并source/创建不同的结果:\nsource\xe2\x80\x94 将源内容复制到目标。source/\xe2\x80\x94 将文件夹源复制到目标。--exclude-from=FILE\xe2\x80\x94FILE是包含要排除的其他文件或目录的文件的名称。--exclude还可能包含通配符:\n--exclude=*/.svn*起始文件夹结构:
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 destination\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 source\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 fileToCopy.rtf\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 fileToExclude.rtf\nRun Code Online (Sandbox Code Playgroud)\n跑步:
\nrsync -av --exclude=\'fileToCopy.rtf\' source/ destination\nRun Code Online (Sandbox Code Playgroud)\n结束文件夹结构:
\n.\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 destination\n\xe2\x94\x82\xc2\xa0\xc2\xa0 \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 fileToExclude.rtf\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 source\n \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 fileToCopy.rtf\n \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 fileToExclude.rtf\nRun Code Online (Sandbox Code Playgroud)\n