您当前所在位置:首页软件教程操作系统Centos 7 文件压缩与解压缩命令详解

Centos 7 文件压缩与解压缩命令详解

归类:操作系统更新时间:2023-12-05 21:04:48作者:互联网人气:211

本篇主要讲解Centos 7的压缩与解压缩命令处理方法,希望对遇到此类问题的朋友能有所帮助,具体的解决办法如下:

 1.zip文件压缩

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

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

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

1
2
3
4
5
6
7
[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 指定解压路径

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

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

1
2
3
[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 [参数] 文件与目录... ...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
[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查看一下是否存在。

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

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

4. tar 解压缩

tar 加参数加文件名

1
2
3
4
5
6
7
8
9
[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

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

下面是其他网友的补充

一、Linux版本

1.png

二、解压缩.tar.gz包到当前目录

tar -xzvf apache-tomcat-7.0.90.tar.gz

2.png
3.png

三、将指定文件压缩成.tar.gz包

tar -czf apache-tomcat-7.0.90.tar.gz ./bin/ ./conf/ ./BUILDING.txt ./README.md

4.png

四、解压缩.war包到当前目录

jar -xvf file.war

5.png
6.png

五、将当前目录所有文件压缩成.war包

jar -cvfM0 file2.war ./

7.png
8.png

六、解压缩.tar包到当前目录

tar -xvf desk.tar

七、将指定文件压缩成.tar包

tar -czf desk2.tar ./file.pdf ./abc/ 

本文地址:http://9zoku.com/os/243.html
版权声明:本文内容来自互联网,该文版权归原作者所有。本站仅提供信息存储空间服务,不拥有文章所有权,不承担相关法律责任。若对本内容有异议或投诉请与管理员联系 5604882#qq.com(请将#换成@)。
操作系统Linux系统