【Linux】.gz文件 压缩与解压缩命令

一、.gz文件压缩与解压缩命令:

1.压缩文件
gzip 源文件
如压缩 b.txt 使用命令 gzip b.txt 注意 压缩为 .gz 文件 源文件会消失
如果想保留源文件 使用命令 gzip -c 源文件 > 压缩文件

[root@localhost ~]# gzip -c b.txt > b.txt.gz
[root@localhost ~]# ll
total 8
-rw-------. 1 root root 951 Apr 24  2017 anaconda-ks.cfg
-rw-r--r--. 1 root root   0 May 19 11:37 b.txt
-rw-r--r--. 1 root root  26 May 19 11:38 b.txt.gz

2.压缩目录
gzip -r 目录
注意 gzip 压缩目录 只会递归地压缩目录下的所有文件 不会压缩目录

[root@localhost ~]# tree -L 3 annie/
annie/
├── 7.txt
└── sm8250
    ├── b.txt
    └── test
        └── 1.txt

2 directories, 3 files
[root@localhost ~]# gzip -r annie
[root@localhost ~]# tree -L 3 annie/
annie/
├── 7.txt.gz
└── sm8250
    ├── b.txt.gz
    └── test
        └── 1.txt.gz

2 directories, 3 files

3.解压

[root@localhost annie]# ll
total 4
-rw-r--r--. 1 root root 26 May 19 11:40 7.txt.gz
drwxr-xr-x. 3 root root 32 May 19 11:41 sm8250
[root@localhost annie]# gzip -d 7.txt.gz 
[root@localhost annie]# ll
total 0
-rw-r--r--. 1 root root  0 May 19 11:40 7.txt
drwxr-xr-x. 3 root root 32 May 19 11:41 sm8250

猜你喜欢

转载自www.cnblogs.com/wucaiyun1/p/12917316.html