压缩文件的两种方式:
bzip2 的压缩:
格式:bzip2 文件名 产生的压缩文件的后缀是XXX.bz2
(这里补充一下,touch是用来创建文件的 touch 文件名)
一次压缩多个文件 bzip2 文件名1 文件名2 文件名 3....
touch a 创建一个文件a
bzip2 把文件压缩成bz2格式的
[leq@localhost leq]$ touch a
[leq@localhost leq]$ ls
a
[leq@localhost leq]$ bzip2 a
[leq@localhost leq]$ ls
a.bz2
bzip2的解压:
格式: bunzip2 文件名.bz2
一次解压多个文件 bunzip2 压缩文件1 压缩文件2 压缩文件3...
[leq@localhost leq]$ bunzip2 a.bz2
[leq@localhost leq]$ ls
a
gzip也是同理
压缩格式:gzip 文件名 产生的压缩文件的后缀是XXX.gz
解压格式:gunzip 文件名.gz
[leq@localhost leq]$ ls
a.gz
[leq@localhost leq]$ gunzip a.gz
[leq@localhost leq]$ ls
a
注:上面的两种压缩只能对文件进行压缩和解压
linux支持的压缩格式: tar gz bz2 zip
tar:对目录和文件进行压缩以及解压缩的处理(完全依赖于参数)
tar压缩中的参数:
-c 压缩
-x 解压缩
-t 在不进行解压的情况下,查看压缩文件的内容
-z 代表gzip命令
-j 代表bzip2命令
-v 显示压缩和解压缩的过程
-f 指定压缩文件名字
对目录(文件夹)的压缩 -cvf
语法: tar -参数 压缩后的文件名.tar 要压缩的文件
[leq@localhost leq]$ ls
a
[leq@localhost leq]$ tar -cvf a.tar a
a
[leq@localhost leq]$ ls
a a.tar
对压缩文件为.tar,进行解压缩 -xvf
格式:tar 参数 压缩文件的名字.tar -C 解压后的目录
(这里补充一下,mkdir是用来创建目录的 格式:mkdir 目录名)
[leq@localhost leq]$ mkdir b
[leq@localhost leq]$ tar -xvf a.tar
a
[leq@localhost leq]$ ls
a a.tar b
[leq@localhost leq]$ tar -xvf a.tar -C b
a
[leq@localhost leq]$ ls
a a.tar b
[leq@localhost leq]$ ls b
a
tar配合解压和压缩gz和bz2格式的文件(放在一个压缩包里)
格式:
gz:
压缩:tar -cvzf 压缩后的文件名.tgz 要压缩的文件
解压:tar -xzvf 要解压的文件名 -C 解压后的目录
bz2:
压缩:tar -cvjf 压缩后的文件名.t.bz1 要压缩的文件
解压:tar -xjvf 要解压的文件名 -C 解压后的目录
例如:把a文件和b目录压缩成bz2格式的
a b
[leq@localhost leq]$ tar -cvjf a.tbz a
a
[leq@localhost leq]$ tar -cvjf a.tbz b
b/
b/a
[leq@localhost leq]$ ls
a a.tbz b
解压:
[leq@localhost leq]$ tar -xjvf a.tbz -C b
b/
b/a
[leq@localhost leq]$ ls b
a b