我正在尝试编写一个简单的bash脚本,将一个文件夹的全部内容(包括隐藏文件和文件夹)复制到另一个文件夹中,但我希望排除某些特定的文件夹。我怎样才能做到这一点呢?
发布于 2010-02-04 02:45:10
使用rsync:
rsync -av --exclude='path1/to/exclude' --exclude='path2/to/exclude' source destination
请注意,使用source
和source/
是不同的。尾部斜杠表示将文件夹source
的内容复制到destination
中。如果没有尾随的斜杠,则表示将文件夹source
复制到destination
中。
或者,如果要排除许多目录(或文件),则可以使用--exclude-from=FILE
,其中FILE
是包含要排除的文件或目录的文件名。
--exclude
还可以包含通配符,如--exclude=*/.svn*
发布于 2010-02-04 01:12:40
将焦油与管道一起使用。
cd /source_directory
tar cf - --exclude=dir_to_exclude . | (cd /destination && tar xvf - )
您甚至可以在ssh中使用这种技术。
发布于 2010-02-04 00:50:47
您可以使用tar和--exclude选项,然后在目标中解压它。例如
cd /source_directory
tar cvf test.tar --exclude=dir_to_exclude *
mv test.tar /destination
cd /destination
tar xvf test.tar
有关详细信息,请参阅tar的手册页
https://stackoverflow.com/questions/2193584
复制相似问题