- gzip与gunzip命令
gzip命令主要用于压缩,产生的gz格式的压缩文件,文件后缀名为.gZ,gunzip命令用于解压缩,将gz格式的压缩文件还原为原来的文件。其用法如下:
[root@localhost ~]# gzip testfile #使用gzip命令压缩当前目录下文件testfile
[root@localhost ~]# II testfile* -rw-r--r--. 1 root root 7818月30 09: 51 testfile.gz
[root@localhost ~]# gunzip testfile.gz
[root@localhost ~]# II testfile* -rW-r--r--. 1 root root 19508月3009: 51 testfile
也可以使用gzip命令来解压缩gz压缩文件,其用法如下:
[root@localhost ~]# gzip -d testfile.gz #使用gzip加-d参数表示解压缩
如果希望将目录下的所有文件压缩,可以使用参数-r,其用法如下:
[root@localhost ~]# gzip -r testdir/
#该命令会将当前目录下的testdir目
2、xz与unxz命令
xz命令主要用于压缩,产生的xz格式的压缩文件,文件后缀名为.xz,unxz命令用于解压缩,
将xz格式的压缩文件还原为原来的文件。其用法如下:
[root@localhost ~]# XZ testfile #使用xz命令压缩当前目录下文件testfile
[root@localhost ~]# II test* #查看当前目录下所有以test开始的文件
-r---.1root root 840 8月30 09: 51 testfile.xz #命令结果,生成testfile.xz压缩文件
[root@localhost ~]# unxz testfile.xz
[root@localhost ~]# Il test*
-rW-r--r--. 1 root root 19508月30 09: 51 testfile
[root@localhost ~]# XZ -d testfile.xZ #使用xz加-d参数表示解压缩
3、bzip2与bunzip2命令
bzip2命令主要用于压缩, 产生的bz2格式的压缩文件,文件后缀名为.bz2,bunzip2命令用于解压缩,将bz2格式的压缩文件还原为原来的文件。其用法如下:
[root@localhost ~]# bzip2 testfile #使用bzip2命令压缩当前目录下文件testfile
也可以使用bzip2命-d令来解压缩bz2压缩文件,其用法如下:
[root@localhost ~]# bzip2 -d testfile.bz2
- gzip/gunzip、bzip2/bunzip2和xz/unxz的区别
项目 压缩与解压缩速度 压缩率 压缩文件后缀
gzip/gunzip 最快 最低 .gz
bzip2/bunzip2 比gzip慢 高于gzip .bz2
xz/unxz 压缩较慢解压较快 最高 .XZ
5、文件打包命令tar
tar命令的主要选项参数有:
(1)动作选项。
-c: 创建打包文件。 -x:释放打包文件。 -t: 列出打包文档中的文件。
(2)压缩选项。
-z:使用gzip压缩与解压打包文件。-j:使用bzip2压缩与解压打包文件。-J:使用xz压缩与解压打包文件。
(3)其他选项。
-f:指明创建、释放或查看的文件打包压缩文件,后必须跟文件的名称
-C:指定要解压的目标位置。 -V:查看详细信息
[root@localhost ~]# tar -czf etc.tar.gz /etc
[root@localhost ~]# tar -tzvf etc.tar.gz
[root@localhost ~]# tar -xzf etc.tar.gz
[root@localhost ~]# tar -cjf etc.tar.bz2
[root@localhost ~]# tar -tjvf etc.tar.bz2
[root@localhost ~]# tar -xjf etc.tar.bz2 -C /boot