linux中的tar命令

原文链接:http://www.tecmint.com/18-tar-command-examples-in-linux/

tar [-options("-" is not necessary)] [name] [path or file(default current directory, if epmty)]

废话不多说,直接拿来用~

创建一个tar文档(打包文档)

tar -cvf [name.tar] [path or file] #c-creat v-view(show the progress) f-file(并不会解释)

tar

创建一个tar.gz文档(打包并压缩)

tar -cvzf [name.tar.gz] [path or file] #z-compress file to **gzip**

tar.gz

创建tar.bz2文档(压缩,另一种形式)

tar cvfj [name.tar.bz2] [path or file] #这次是 **j**

tar.bz2.png

解压一个tar文件 (x-extract-uncompress)

tar -xvf [name.tar or name.tar.gz or name.tar.bz2] -c [path]
or
tar xvf [name.tar or name.tar.gz or name.tar.bz2] #empty for current directory

untar

untar.gz

untar.gz.bz2

查看压缩文件目录(list)

tar tvf name.tar

list

list2

list3

提取文档中的某一个文件

tar -xvf name.tar file_name
or
tar --extract --file=name.tar file_name

single

解压文档中的某一文件

tar -zxvf name.tar.gz file_name
or
tar --extract --file=name.tar.gz file_name

untar_single

tar -jxvf name.tar.bz2 file_name
or
...a long long command and I don't think U will be willing to use it...

untar_single_bz2

解压/提取 文件中的多个文件

上图吧...

multiple

用正则去匹配文档中的文件,并解压提取出来

--wildcards "*[Aa].wow"

wildcards

向文档中添加某些文件(包括压缩的和非压缩的)

直接上图啦

add

add

查验文档是啥(在你不知道压缩文档是什么类型的时候用)

W(大写)代表verify(不要问我什么鬼,我也不知道为啥w就代表verify了)

verify

查看文档的大小(并不是经常用)

通过管道传递到 wc -c 来查看

check

另附英文版参数解释:

c – create a archive file.
x – extract a archive file.
v – show the progress of archive file.
f – filename of archive file.
t – viewing content of archive file.
j – filter archive through bzip2.
z – filter archive through gzip.
W – Verify a archive file.
wildcards – Specify patters in unix tar command.
comments powered by Disqus