wc -l #查看文件的行数
file #查看文件的类型
zcat #可以查看gz压缩文件的内容
bzcat #可以查看bz2压缩文件内容
xzcat #可以查看xz压缩文件得内容
linux下常见的压缩文件:
zip gz bz2 xz tar.gz tar.bz2 tar.xz
一、gzip压缩工具
1.
gzip
后面接文件名,就可以压缩文件,gzip不支持压缩目录
1. [root@localhost ys]# du -sh test.txt #test.txt的文件大小为4M
4.0M test.txt
2. [root@localhost ys]# gzip test.txt #使用gzip工具压缩test.t
xt
3. [root@localhost ys]# ls #压缩后的文件名变为test.txt.gz
test.txt.gz
4. [root@localhost ys]# du -sh test.txt.gz #大小变为636K
636K test.txt.gz
2.
gzip -d 解压文件
[root@localhost ys]# gzip -d test.txt.gz #解压
test.txt.gz
[root@localhost ys]# ls
test.txt
[root@localhost ys]# du -sh test.txt #解压后文件大小变为2.5M
2.5M test.txt
3.
gzip -[1-9] gzip压缩是由级别的,在压缩的时候可以指定压缩级别,默认6级别,数字越大,压缩级别越大
[root@localhost ys]# gzip -1 test.txt #指定1级别压缩
[root@localhost ys]# du -sh test.txt.gz #压缩的文件大小752k,相比6级别压缩后更大
752K test.txt.gz
4.
gunzip 同样可以解压文件
[root@localhost ys]# gunzip test.txt.gz
[root@localhost ys]# ls
test.txt
5.
gzip -c 压缩或解压缩文件的时候保留原文件
1. [root@localhost ys]# gzip -c test.txt > /tmp/aa.txt.gz #压缩test.txt文件,并将压缩后的文件放到/tmp/下,命名为
aa.txt.gz
2. [root@localhost ys]# ls #压缩前的文件还在
test.txt
3. [root@localhost ys]# ls /tmp/aa.txt.gz
/tmp/aa.txt.gz
4. [root@localhost ys]# gzip -d -c /tmp/aa.txt.gz > /tmp/ys/2.txt #解压缩文件,并将解压后的文件放到/tmp/ys/下,命名为2.txt
5. [root@localhost ys]# ls
2.txt test.txt
6. [root@localhost ys]# ls /tmp/aa.txt.gz #原来的压缩文件仍然存在
/tmp/aa.txt.gz
二、bzip2压缩工具
1.
bzip2 后面接文件名就可以压缩文件,用法和gzip差不多,比gzip压缩得更狠
1. [root@localhost ys]# bzip2 test.txt #使用bzip2压缩文件test.txt
2. [root@localhost ys]# du -sh test.txt.bz2 #可以看到压缩后的文件大小220k,相对gzip来说压缩得更小,但是这意味着耗费得CPU资源更多
220K test.txt.bz2
3. [root@localhost ys]# ls
2.txt test.txt.bz2
2.
bzip2 -d bunzip2 都可以用来解压bz2文件
[root@localhost ys]# bzip2 -d test.txt.bz2
[root@localhost ys]# ls
2.txt test.txt
3.
bzip2 -c 压缩或解压缩文件的时候保留原文件,用法和gzip一样
4.
bzip2 -[1-9] bzip2同样可以指定压缩级别,默认级别为9,
三、xz压缩工具
1.
xz 后面接文件名就可以压缩文件,比bzip2压缩得更狠
2.
xz -[1-9] xz同样可以指定压缩级别,默认为6级别
3.
xz -d unxz 这两个文件用来解压缩
4.
xz -c
压缩或解压缩文件的时候保留原文件