Linux Centos 7 压缩和解压缩命令

本文详细介绍了Linux Centos 7中如何使用zip和tar进行文件的压缩和解压缩操作。包括zip命令的使用,如压缩和解压缩文件,以及tar命令的各种参数,如-c创建压缩文件,-x解开压缩文件,-t查看压缩文件内容,-z使用gzip压缩等。通过实例演示了压缩和解压缩的步骤,帮助读者掌握这些基本操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.zip文件压缩

语法:zip 加压缩后的文件名 加要压缩的文件名。

[root@localhost ~]# zip test.zip test.txt
  adding: test.txt (deflated 100%)
[root@localhost ~]# 

后面出现进度条百分比数字说明已经压缩好了然后你在ll验证一下看看有没有你命名的文件包。

[root@localhost ~]# ll
总用量 820004
-rw-------. 1 root root      1587 3月  22 16:58 anaconda-ks.cfg
-rw-r--r--. 1 root root      1635 3月  22 17:00 initial-setup-ks.cfg
-rw-r--r--. 1 root root 838860800 3月  26 14:56 test.txt
-rw-r--r--. 1 root root    814270 3月  26 14:57 test.zip
[root@localhost ~]# 

2. zip 文件解压缩

zip 解压缩就在zip 前面加个un ,要指定路径的话就加个 -d

语法就是 unzip 要解压的文件名 -d 指定解压路径

[root@localhost ~]# unzip test.zip -d /tmp/
Archive:  test.zip
  inflating: /tmp/test.txt           
[root@localhost ~]# 

是不是很简单,然后再ls 加你指定的路径去验证一下有没有你解压出来的文件,有的话就说明你成功了。恭喜你成功学会了zip 压缩和zip 解压!!!然后我们继续....

[root@localhost ~]# ls /tmp
test.txt
[root@localhost ~]# 

3.tar压缩与解压缩

tar参数有

-c  建立一个压缩文件

-x  解开一个压缩文件

-t   查看tar压缩文件里面的文件

-z  使用gzip压缩

-j  使用bzip2压缩

-v  压缩过程中显示文件*(常用)但不建议用在背景执行过程

-f   使用档名,注意:f之后要立即接档名,不能再接参数

注意:以上是tar常用的参数,以上三个参数不能同时使用,只能存在一个!!!

tar 创建一个文件命令

语法:tar [参数] 文件与目录... ...

[root@localhost ~]# tar -czvf user /etc
tar: 从成员名中删除开头的“/”
/etc/
/etc/fstab
/etc/crypttab
/etc/mtab
/etc/resolv.conf
/etc/fonts/
/etc/fonts/conf.d/
/etc/fonts/conf.d/57-dejavu-serif.conf
/etc/fonts/conf.d/65-1-vlgothic-gothic.conf
/etc/fonts/conf.d/31-cantarell.conf
/etc/fonts/conf.d/65-0-lohit-nepali.conf
/etc/fonts/conf.d/59-liberation-mono.conf

后面还有一堆看不懂的东西然后就到后面在ls查看一下是否存在。

[root@localhost ~]# ls
anaconda-ks.cfg  initial-setup-ks.cfg  test.txt  test.zip  user
[root@localhost ~]# 

然后再说解压缩.....

4. tar 解压缩

tar 加参数加文件名 

[root@localhost ~]# tar -xvf user
etc/
etc/fstab
etc/crypttab
etc/mtab
etc/resolv.conf
etc/fonts/
etc/fonts/conf.d/
etc/fonts/conf.d/57-dejavu-serif.conf

后面还有一堆的解压过程就省略了反正就是解压成功了

CentOS 7中,你可以使用zip命令进行文件的压缩和解压缩操作。以下是zip命令的基本用法: 1. 安装zip命令:使用yum命令进行安装,运行以下命令: ``` yum install -y zip ``` 2. 压缩文件:使用zip命令对指定的目录进行压缩,基本格式为: ``` zip [参数 [压缩后的文件名 [打包的目录路径] ``` 例如,如果你需要压缩文件夹a下所有的内容,可以执行以下命令: ``` zip -r a.zip a ``` 3. 解压zip文件:使用unzip命令压缩文件进行解压缩,基本格式为: ``` unzip [压缩文件名.zip] ``` 例如,如果你需要解压缩名为xxx.zip的文件到当前路径下,可以执行以下命令: ``` unzip xxx.zip ``` 希望这些信息对你有所帮助!<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [Linux(Centos7)基本操作(1):文件压缩和解压(tar、zip)](https://blog.csdn.net/qq_40253126/article/details/131663574)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [CentOS7中zip压缩和unzip解压缩命令详解](https://blog.csdn.net/xkdlzy/article/details/116806331)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [javasnmp源码-centos-script:centos脚本](https://download.csdn.net/download/weixin_38686231/19387122)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值