命令簡介
SYNOPSIS
tar [OPTION...] [FILE]...
Common options:
-f, --file=ARCHIVE
use archive file or device ARCHIVE
-j, --bzip2
filter the archive through bzip2
-z, --gzip
filter the archive through gzip
-v, --verbose
verbosely list files processed
Main operation mode:
-c, --create
create a new archive
-t, --list
list the contents of an archive
-x, --extract, --get
extract files from an archive
打包多個文件(夾)
之前以為使用tar命令必須先把所有內容放到一個文件夾下,然后在對這個文件夾打包。其實,tar命令可以一次性對多個文件(夾)進行打包,非常便捷,例如:
#當前目錄下有A,B,C目錄和a,b,c文件,只想對A,B,a進行打包,命令如下:
tar czf foo.tar.gz A B a
排除文件(夾)
如果我們想對一個代碼倉庫打包,需要排除.git版本庫,因為其非常大,可以使用下面的命令:
tar czf foo.tar.gz --exclude=.git foo
注意
:如果將上述命令寫為tar czf foo.tar.gz foo --exclude=.git
,--exclude選項將不會生效,因為這不符合tar命令的語法。