轉載自:
http://www.vktone.com/articles/linux-tar-ignore-some-files.html
在Linux下,常用tar對文件或目錄歸檔壓縮,有時候需要忽略某些文件或目錄,怎麼做呢?
原來,tar命令有個長參數 --exclude 可以用來指定排除掉的文件目錄。
[root@mos178 usr]# ls motix bin bin.1153887679 bin.20080407zhy_something_wrong cfg cfg.1153887679 cfg.20070425.tar.gz log motix0405.tar.gz run [root@mos178 usr]# tar zcf motix.20130121a.tar.gz motix --exclude log --exclude "*.gz" [root@mos178 usr]# tar ztvf motix.20130121a.tar.gz ... [root@mos178 usr]#
關鍵是要總結出要忽略文件的模式來。
[root@sunrise root]# tar zcf work181.20130121a.tar.gz work181 --exclude log --exclude "*20*" --exclude bin
[root@sunrise root]#
與tar --exclude相關的參數說明如下:
--exclude PATTERN exclude files based upon PATTERN -X, --exclude-from FILE exclude files listed in FILE --wildcards use wildcards with --exclude --wildcards-match-slash wildcards match slashes (/) with --exclude --no-anchored match any subsequenceof the name’s components with --exclude --no-ignore-case use case-sensitive matching with --exclude --no-wildcards don’t use wildcards with --exclude --no-wildcards-match-slash wildcards do not match slashes (/) with --exclude