关于unix:Tar:创建归档排除目录,但一个目录除外

Tar: create archive exclude directories except one

我有一些目录和一些文件

1
2
3
4
5
6
7
8
9
dir_archive/somedir1
dir_archive/somedir2
dir_archive/somedir3
dir_archive/mydir
dir_archive/mydir/excludedir1
dir_archive/mydir/excludedir2
dir_archive/mydir/excludedir3
dir_archive/mydir/many_other_directories...
dir_archive/mydir/my_archive_dir

我要创建tar(gz)archive dir_archive.tar.gz,所有文件和目录都不包括

1
2
3
4
dir_archive/mydir/excludedir1
dir_archive/mydir/excludedir2
dir_archive/mydir/excludedir3
dir_archive/mydir/many_other_directories...

但包括

1
dir_archive/mydir/my_archive_dir

我不想对每个目录使用--exclude

1
tar cvfz dir_archive.tar.gz --exclude=dir_archive/mydir/excludedir1 --exclude=dir_archive/mydir/excludedir2 --exclude=dir_archive/mydir/excludedir3

我试着用--add-file,但不起作用:

1
tar cvfz dir_archive.tar.gz --exclude=dir_archive/mydir --add-file=dir_archive/mydir/my_archive_dir dir_archive

存在一些简单的方法吗?谢谢


一路excluding摇篮第一mydir然后my_archive_dirappending the theP></

1
2
3
tar cvf dir_archive.tar --exclude=dir_archive/mydir dir_archive
tar rvf dir_archive.tar dir_archive/mydir/my_archive_dir
gzip dir_archive.tar

不幸的是他/她不zipped appending工作与档案。P></

--excludeas the option需要知道if the argument模式,dirs of the names are similar to be excluded,你可以避免呢还是the archive目录包括布尔P></

1
tar cvfz dir_archive.tar.gz --exclude=dir_archive/mydir/exclude* dir_archive

is also possible to create a en文件与档案名称???你想给list to that included和焦油与期权(或相似--files-from-Tor the files to be excluded时尚列表和列表与-X给the option)。P></

1
2
3
4
5
6
7
filelist.txt:
dir_archive
dir_archive/temp1
dir_archive/mydir
dir_archive/mydir/temp2
dir_archive/mydir/my_archive_dir
dir_archive/mydir/my_archive_dir/temp7
1
tar cvfz dir_archive.tar.gz --no-recursion --files-from filelist.txt