编程开源技术交流,分享技术与知识

网站首页 > 开源技术 正文

压缩工具gzip、bzip2、xz(压缩工具可以作为加密软件使用吗)

wxchong 2024-07-20 08:51:19 开源技术 38 ℃ 0 评论

Linux常见压缩文件扩展名如下:

.zip,.gz,.bz2,.xz,.tar.gz,.tar.bz2,.tar.xz

压缩文件解压后可能与源文件大小不一致。

gzip压缩工具

  • 命令格式: gzip 文件名
  • 不能压缩目录
[root@centos01 d6]# ls -lh 1.txt
-rw-r--r--. 1 root root 1.3M Sep 30 07:38 1.txt
[root@centos01 d6]#
[root@centos01 d6]# gzip 1.txt # 压缩1.txt
[root@centos01 d6]# ls
1.txt.gz
[root@centos01 d6]# ls -lh 1.txt.gz
-rw-r--r--. 1 root root 358K Sep 30 07:38 1.txt.gz
[root@centos01 d6]# gzip -d 1.txt.gz # 解压缩1.txt.gz
[root@centos01 d6]# ls
1.txt
[root@centos01 d6]# gunzip 1.txt.gz # gunzip解压1.txt.gz
[root@centos01 d6]# ls
1.txt
[root@centos01 d6]# gzip -1 1.txt # 默认压缩级别6,范围1-9 
[root@centos01 d6]# ls
1.txt.gz
[root@centos01 d6]# zcat 1.txt.gz | head -n 5 # 查看压缩文件(加压后打开)
# This is an example configuration file for the LVM2 system.
# It contains the default settings that would be used if there was no
# /etc/lvm/lvm.conf file.
#
# Refer to 'man lvm.conf' for further information including the file layout.
[root@centos01 d6]# gzip -c 1.txt > 1.txt.gz # 压缩时不删除文件,并输出到指定文件
[root@centos01 d6]# ls
1.txt 1.txt.gz
[root@centos01 d6]# gunzip -c 1.txt.gz > 1.cp.txt # 不删除压缩文件,解压为指定文件
[root@centos01 d6]# ls
1.cp.txt 1.txt 1.txt.gz

bzip2压缩工具

  • 安装工具: yum install -y bzip2
  • 命令格式: bzip2 文件名
  • 不支持压缩目录
[root@centos01 d6]# bzip2 1.txt # 压缩1.txt
[root@centos01 d6]# ls -l
total 1840
-rw-r--r--. 1 root root 1361328 Sep 30 07:50 1.cp.txt
-rw-r--r--. 1 root root 149229 Sep 30 07:38 1.txt.bz2
-rw-r--r--. 1 root root 365757 Sep 30 07:48 1.txt.gz
[root@centos01 d6]# bzip2 -d 1.txt.bz2 # 解压缩1.txt.bz2
[root@centos01 d6]# ls
1.cp.txt 1.txt 1.txt.gz
[root@centos01 d6]# bzip2 1.txt
[root@centos01 d6]# bunzip2 1.txt.bz2 # 解压缩1.txt.bz2
[root@centos01 d6]# bzip2 -c 1.txt > 1.tmp.bz2 # 压缩时不删除文件,并输出到指定文件
[root@centos01 d6]# ls
1.cp.txt 1.tmp.bz2 1.txt 1.txt.gz
[root@centos01 d6]# bzip2 -d -c 1.tmp.bz2 > 1.cp2.txt # 压缩时不删除文件,并输出到指定文件
[root@centos01 d6]# ls
1.cp2.txt 1.cp.txt 1.tmp.bz2 1.txt 1.txt.gz
[root@centos01 d6]# bzip2 -9 1.cp.txt # -9级别,范围1-9
[root@centos01 d6]# ls
1.cp2.txt 1.cp.txt.bz2 1.tmp.bz2 1.txt 1.txt.gz
[root@centos01 d6]# bzcat 1.tmp.bz2 | head -n 10 # bz2压缩文件查看
# This is an example configuration file for the LVM2 system.
# It contains the default settings that would be used if there was no
# /etc/lvm/lvm.conf file.
#
# Refer to 'man lvm.conf' for further information including the file layout.
#
# Refer to 'man lvm.conf' for information about how settings configured in
# this file are combined with built-in values and command line options to
# arrive at the final values used by LVM.
#

xz压缩工具

  • 命令格式: xz 2.txt
  • 使用基本和gzip、bzip2一样
[root@centos01 d6]# xz 2.txt
[root@centos01 d6]# xz -d 2.txt.xz
[root@centos01 d6]# xz 2.txt
[root@centos01 d6]# unxz 2.txt.xz
[root@centos01 d6]# xz -c 2.txt > 2.cp.txt.xz
[root@centos01 d6]# xz -d -c 2.cp.txt.xz > 2.cp.txt
[root@centos01 d6]# xz 2.txt
[root@centos01 d6]# xzcat 2.txt.xz | head -n 10
# This is an example configuration file for the LVM2 system.
# It contains the default settings that would be used if there was no
# /etc/lvm/lvm.conf file.
#
# Refer to 'man lvm.conf' for further information including the file layout.
#
# Refer to 'man lvm.conf' for information about how settings configured in
# this file are combined with built-in values and command line options to
# arrive at the final values used by LVM.
#

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表