Linux常用命令(7)——解压缩命令

压缩和解压缩命令

在Linux中不以后缀名来区分文件,后缀名主要用来帮助管理员区分压缩格式

.zip

不常见

压缩 zip

压缩命令就是zip,其基本信息如下:

  • 命令名称:zip
  • 英文原意:package and compress (archive) files。
  • 所在路径:/usr/bin/zip
  • 执行权限:所有用户
  • 功能描述:压缩目录或文件
[root@localhost ~]# zip [选项] 压缩包名 源文件或源目录
选项:
	-r: 压缩目录

例子:
[root@localhost ~]# zip ana.zip anaconda-ks.cfg 

解压 unzip

".zip"格式的解压缩命令是unzip,其基本信息如下:

  • 命令名称:unzip
  • 英文原意:list,test and extract compressed files in a ZIP archive
  • 所在路径:/usr/bin/unzip
  • 执行权限:所有用户
  • 功能描述:列表、测试和提取压缩文件中的文件
[root@localhost~]# unzip [选项] 压缩包名称
选项:
	-d:			指定解压缩位置
例子:
[root@localhost~]# unzip -d /tmp/ ana.zip

.gz

不会打包

压缩gzip

使用gzip命令进行压缩,其基本信息如下:

  • 命令名称:gzip
  • 英文原意:compress or expand files
  • 所在路径:/usr/bin/gzip
  • 执行权限:所有用户
  • 功能描述:压缩文件或目录
[root@localhost~]# gzip [选项] 源文件
选项:
	-c:			将压缩数据输出到标准输出中,可以用于保留源文件
	-d:			解压缩
	-r:			压缩目录
例子:
[root@localhost ~]# gzip -c anaconda-ks.cfg > anaconda-ks.cfg.gz
  #使用-c 选项,但是不让压缩数据输出到屏幕上,而是重定向到压缩文件中
  #这样可以在压缩文件的同时不删除源文件

解压缩 gunzip

如果要解压缩“.gz”格式,那么使用“gzip -d 压缩包”和“gunzip 压缩包”命令都可以。其基本信息如下:

  • 命令名称:gunzip
  • 英文原意:compress or expand files
  • 所在路径:/usr/bin/gunzip
  • 执行权限:所有用户
  • 功能描述:解压缩文件或目录
例子:
[root@localhost ~]# gunzip install.log.gz
[root@localhost ~]# gzip -d anaconda-ks.cfg.gz
两个命令都可以解压缩“.gz”格式

.bz2

不能压缩目录

压缩bzip2

  • 命令名称:bzip2
  • 英文原意:a block-sorting file compressor
  • 所在路径:/usr/bin/bzip2
  • 执行权限:所有用户
  • 功能描述:.bz2 格式的压缩命令
[root@localhost ~]# bzip2 [选项] 源文件
	选项:
	-d: 解压缩
	-k: 压缩时,保留源文件
	-v: 显示压缩的详细信息
	
例如:
[root@localhost ~]# bzip2 anaconda-ks.cfg
#压缩成.bz2 格式
[root@localhost ~]# bzip2 -k install.log.syslog
#保留源文件压缩

解压缩bunzip2

  • 命令名称:bunzip2
  • 英文原意:a block-sorting file compressor。
  • 所在路径:/usr/bin/bunzip2
  • 执行权限:所有用户
  • 功能描述:.bz2 格式的解压缩命令
[root@localhost ~]# bunzip2 anaconda-ks.cfg.bz2
[root@localhost ~]# bzip2 -d install.log.syslog.bz2
#两个命令都可以解压缩

.tar

只打包

打包

  • 命令名称:tar
  • 英文原意:tar
  • 所在路径:/usr/bin/tar
  • 执行权限:所有用户
  • 功能描述:打包与解包命令
[root@localhost ~]# tar [选项] [-f 压缩包名] 源文件或目录
    选项:
    -c: 打包
    -f: 指定压缩包的文件名。压缩包的扩展名是用来给管理员识别格式的,所以一定要正确指定扩展名
    -v: 显示打包文件过程
    [root@localhost ~]# tar -cvf anaconda-ks.cfg.tar anaconda-ks.cfg
    #打包,不会压缩

解包

[root@localhost ~]# tar [选项] 压缩包
    选项:
    -x: 解打包
    -f: 指定压缩包的文件名
    -v: 显示解打包文件过程
    -t: 测试,就是不解打包,只是查看包中有哪些文件
    -C() 目录:指定解打包位置
    例如
    [root@localhost ~]# tar -xvf anaconda-ks.cfg.tar
    #解打包到当前目录下

.tar.gz和.tar.bz2

使用 tar 命令直接打包压缩。

命令格式如下:
    [root@localhost ~]# tar [选项] 压缩包 源文件或目录
    选项:
    -z: 压缩和解压缩“.tar.gz”格式
    -j: 压缩和解压缩“.tar.bz2”格式
    例如:.tar.gz 格式
    [root@localhost ~]# tar -zcvf tmp.tar.gz /tmp/
    #把/tmp/目录直接打包压缩为“.tar.gz”格式
    [root@localhost ~]# tar -zxvf tmp.tar.gz
		#解压缩与解打包“.tar.gz”格式


例如:.tar.bz2 格式
  [root@localhost ~]# tar -jcvf tmp.tar.bz2 /tmp/
  #打包压缩为“.tar.bz2”格式,注意压缩包文件名
  [root@localhost ~]# tar -jxvf tmp.tar.bz2
	#解压缩与解打包“.tar.bz2”格式


再举几个例子:
  [root@localhost ~]# mkdir test
  [root@localhost ~]# touch test/abc
  [root@localhost ~]# touch test/bcd
  [root@localhost ~]# touch test/cde
  #建立测试目录和测试文件
  [root@localhost ~]# tar -zcvf test.tar.gz test/
  #压缩
  [root@localhost ~]# tar -ztvf test.tar.gz
  #只查看,不解压
  [root@localhost ~]# tar -zxvf test.tar.gz -C /tmp
  #解压缩到指定位置
  [root@localhost ~]# tar -zxvf test.tar.gz -C /tmp test/cde
  #只解压压缩包中的特定文件,到指定位置
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
Linux中,可以使用unrar命令解压.7z文件。使用unrar命令的参数-x表示解压缩文件,并且按原始目录树解压,-r表示递归解压缩所有的子文件夹,-o用于指定解压到的目录。因此,解压.7z文件的命令可以是:unrar x -r -o DestPath test.7z。其中,DestPath是你想要解压到的目录路径。\[1\]\[2\]如果你的系统中没有安装unrar命令,你可以通过以下步骤进行安装:首先,使用wget命令下载rarlinux-x64-610.tar.gz文件。然后,使用tar命令解压该文件到/opt目录下。接下来,进入/opt/rar/目录,使用make命令编译并安装unrar。完成安装后,你就可以使用unrar命令解压.7z文件了。\[3\] #### 引用[.reference_title] - *1* *3* [linux解压rar和7z压缩文件](https://blog.csdn.net/kali_yao/article/details/122789442)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] - *2* [Linux系统tar、rar、7z、zip压缩解压缩命令使用](https://blog.csdn.net/weixin_42081389/article/details/86676056)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

阿瑾~

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值