tar、gzip、zip压缩命令
which命令
查找PATH环境变量中的文件,Linux内置命令不在path中
[root@timy-test-k8s01 ~]# which python
/usr/bin/python
whereis命令
whereis命令用来定位指定的二进制程序、源代码文件和man手册页等相关文件的路径
[root@timy-test-k8s01 ~]# whereis python
python: /usr/bin/python /usr/bin/python2.7 /usr/lib/python2.7 /usr/lib64/python2.7 /etc/python /usr/include/python2.7 /usr/share/man/man1/python.1.gz
tar命令
tar命令在Linux系统里,可以实现对多个文件进行,压缩、打包、解包
打包:将一大堆文件或目录汇总成一个整体
压缩:将大文件压缩成小文件,节省磁盘空间
语法:
tar (选项) (参数)
-A或--catenate: 新增文件到以存在的备份文件;
-B: 设置区块大小;
-c或--create: 建立新的备份文件;
-C<目录>: 这个选项用在解压缩,若要在特定目录解压缩,可以使用这个选项;
-d: 记录文件的差别;
-x或--extract或--get: 从备份文件中还原文件;
-t或--list: 列出备份文件的内容;
-z或--gzip或--ungzip: 通过gzip指令处理备份文件;
-Z或--compress或--uncompress: 通过compress指令处理备份文件
-f<备份文件>或--file=<备份文件>: 指定备份文件;
-v或--verbose: 显示指令执行过程;
-r: 添加文件到已经压缩的文件
-u: 添加改变了和现有的文件到已经存在的压缩文件;
-j: 支持bzip2解压文件;
-v: 显示操作过程
-l: 文件系统边界设置;
-k: 保留原有文件不覆盖
-m: 保留文件不被覆盖
-w: 确认压缩文件的正确性
-p或--same-permissions: 用原来的文件权限还原文件
-p或--absoulte-names: 文件名使用绝对名称,不移除文件名称前的"/"号;不建议使用
-N <日期格式> 或 --newer=<日期时间>: 只将较指定日期更新的文件保存到备份文件里
--exclude=<范本样式>: 排除符合范本样式的文件
-h --dereference跟踪符号链接;将它们所指向的文件归档并输出
案例
1.仅打包,不压缩
#tar 参数 包裹文件名 需要打包的文件
tar -cvf alltemp.tar ./*
[root@timy-test-k8s01 Desktop]# tar -cvf alltemp.tar ./* ./0test/ ./1test/ ./2test/ ./3test/ ./4test/ ./5test/ ./6test/ ./7test/ ./8test/ ./9test/ ./alex.txt ./cesh1.txt ./ceshi1.txt ./ceshi.xt ./mjj.txt ./test.sh ./test.txt[root@timy-test-k8s01 Desktop]# ll total 44 drwxr-xr-x. 2 root root 6 Apr 23 01:45 0test drwxr-xr-x. 2 root root 6 Apr 23 01:45 1test drwxr-xr-x. 2 root root 6 Apr 23 01:45 2test drwxr-xr-x. 2 root root 6 Apr 23 01:45 3test drwxr-xr-x. 2 root root 6 Apr 23 01:45 4test drwxr-xr-x. 2 root root 6 Apr 23 01:45 5test drwxr-xr-x. 2 root root 6 Apr 23 01:45 6test drwxr-xr-x. 2 root root 6 Apr 23 01:45 7test drwxr-xr-x. 2 root root 6 Apr 23 01:45 8test drwxr-xr-x. 2 root root 6 Apr 23 01:45 9test -rw-r--r--. 1 root root 17 Apr 22 05:25 alex.txt -rw-r--r--. 1 root root 20480 Apr 23 21:56 alltemp.tar -rw-r--r--. 1 root root 14 Apr 16 04:32 cesh1.txt -rw-r--r--. 1 root root 39 Apr 16 04:36 ceshi1.txt -rw-r--r--. 1 root root 0 Apr 16 05:31 ceshi.xt -rw-r--r--. 1 root root 14 Apr 19 21:34 mjj.txt -rwxr-xr-x. 1 root root 66 Apr 16 04:14 test.sh -rw-r--r--. 1 root root 43 Apr 23 02:55 test.txt
2.对Desktop下的所有文件进行打包并压缩,节省磁盘空间
tar -czvf alltemp1.tar.gz ./* #./*代表当前目录下的所有文件
[root@timy-test-k8s01 Desktop]# tar -czvf alltemp1.tar.gz ./* ./0test/ ./1test/ ./2test/ ./3test/ ./4test/ ./5test/ ./6test/ ./7test/ ./8test/ ./9test/ ./alex.txt ./alltemp.tar ./cesh1.txt ./ceshi1.txt ./ceshi.xt ./mjj.txt ./test.sh ./test.txt [root@timy-test-k8s01 Desktop]# ll total 48 drwxr-xr-x. 2 root root 6 Apr 23 01:45 0test drwxr-xr-x. 2 root root 6 Apr 23 01:45 1test drwxr-xr-x. 2 root root 6 Apr 23 01:45 2test drwxr-xr-x. 2 root root 6 Apr 23 01:45 3test drwxr-xr-x. 2 root root 6 Apr 23 01:45 4test drwxr-xr-x. 2 root root 6 Apr 23 01:45 5test drwxr-xr-x. 2 root root 6 Apr 23 01:45 6test drwxr-xr-x. 2 root root 6 Apr 23 01:45 7test drwxr-xr-x. 2 root root 6 Apr 23 01:45 8test drwxr-xr-x. 2 root root 6 Apr 23 01:45 9test -rw-r--r--. 1 root root 17 Apr 22 05:25 alex.txt -rw-r--r--. 1 root root 656 Apr 23 22:02 alltemp1.tar.gz -rw-r--r--. 1 root root 20480 Apr 23 21:56 alltemp.tar -rw-r--r--. 1 root root 14 Apr 16 04:32 cesh1.txt -rw-r--r--. 1 root root 39 Apr 16 04:36 ceshi1.txt -rw-r--r--. 1 root root 0 Apr 16 05:31 ceshi.xt -rw-r--r--. 1 root root 14 Apr 19 21:34 mjj.txt -rwxr-xr-x. 1 root root 66 Apr 16 04:14 test.sh -rw-r--r--. 1 root root 43 Apr 23 02:55 test.txt
3.解压缩文件,将之前的压缩的文件解压到Desktop路径
tar -xzvf alltemp1.tar.gz
[root@timy-test-k8s01 Desktop]# tar -xzvf alltemp1.tar.gz ./0test/ ./1test/ ./2test/ ./3test/ ./4test/ ./5test/ ./6test/ ./7test/ ./8test/ ./9test/ ./alex.txt ./alltemp.tar ./cesh1.txt ./ceshi1.txt ./ceshi.xt ./mjj.txt ./test.sh ./test.txt [root@timy-test-k8s01 Desktop]# ll total 48 drwxr-xr-x. 2 root root 6 Apr 23 01:45 0test drwxr-xr-x. 2 root root 6 Apr 23 01:45 1test drwxr-xr-x. 2 root root 6 Apr 23 01:45 2test drwxr-xr-x. 2 root root 6 Apr 23 01:45 3test drwxr-xr-x. 2 root root 6 Apr 23 01:45 4test drwxr-xr-x. 2 root root 6 Apr 23 01:45 5test drwxr-xr-x. 2 root root 6 Apr 23 01:45 6test drwxr-xr-x. 2 root root 6 Apr 23 01:45 7test drwxr-xr-x. 2 root root 6 Apr 23 01:45 8test drwxr-xr-x. 2 root root 6 Apr 23 01:45 9test -rw-r--r--. 1 root root 17 Apr 22 05:25 alex.txt -rw-r--r--. 1 root root 656 Apr 23 22:02 alltemp1.tar.gz -rw-r--r--. 1 root root 20480 Apr 23 21:56 alltemp.tar -rw-r--r--. 1 root root 14 Apr 16 04:32 cesh1.txt -rw-r--r--. 1 root root 39 Apr 16 04:36 ceshi1.txt -rw-r--r--. 1 root root 0 Apr 16 05:31 ceshi.xt -rw-r--r--. 1 root root 14 Apr 19 21:34 mjj.txt -rwxr-xr-x. 1 root root 66 Apr 16 04:14 test.sh -rw-r--r--. 1 root root 43 Apr 23 02:55 test.txt
4.列出压缩文件中的内容
tar -ztvf alltmp1.tar.gz
[root@timy-test-k8s01 Desktop]# tar -ztvf alltemp1.tar.gz drwxr-xr-x root/root 0 2022-04-23 01:45 ./0test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./1test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./2test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./3test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./4test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./5test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./6test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./7test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./8test/ drwxr-xr-x root/root 0 2022-04-23 01:45 ./9test/ -rw-r--r-- root/root 17 2022-04-22 05:25 ./alex.txt -rw-r--r-- root/root 20480 2022-04-23 21:56 ./alltemp.tar -rw-r--r-- root/root 14 2022-04-16 04:32 ./cesh1.txt -rw-r--r-- root/root 39 2022-04-16 04:36 ./ceshi1.txt -rw-r--r-- root/root 0 2022-04-16 05:31 ./ceshi.xt -rw-r--r-- root/root 14 2022-04-19 21:34 ./mjj.txt -rwxr-xr-x root/root 66 2022-04-16 04:14 ./test.sh -rw-r--r-- root/root 43 2022-04-23 02:55 ./test.txt
5.单独的取出压缩文件中的内容
tar -zxvf alltemp.tar.gz ./7test #从alltemp.tar.gz中拷贝出7test文件
[root@timy-test-k8s01 Desktop]# tar -zxvf alltemp1.tar.gz ./7test ./7test/ [root@timy-test-k8s01 Desktop]# ls 7test alltemp1.tar.gz
6.指定目录解压缩
[root@timy-test-k8s01 Desktop]# mkdir alltemp #创建alltemp文件夹 [root@timy-test-k8s01 Desktop]# ls 7test alltemp alltemp1.tar.gz [root@timy-test-k8s01 Desktop]# tar -zxvf alltemp1.tar.gz -C ./alltemp/ #将alltemp.tar.gz,指定解压到alltemp文件夹,-C指定解压路径 ./0test/ ./1test/ ./2test/ ./3test/ ./4test/ ./5test/ ./6test/ ./7test/ ./8test/ ./9test/ ./alex.txt ./alltemp.tar ./cesh1.txt ./ceshi1.txt ./ceshi.xt ./mjj.txt ./test.sh ./test.txt
7.排除文件解压缩 --exclude
[root@timy-test-k8s01 Desktop]# tar -zxvf alltemp1.tar.gz #查看压缩文件内容 ./0test/ ./1test/ ./2test/ ./3test/ ./4test/ ./5test/ ./6test/ ./7test/ ./8test/ ./9test/ ./alex.txt ./alltemp.tar ./cesh1.txt ./ceshi1.txt ./ceshi.xt ./mjj.txt ./test.sh ./test.txt [root@timy-test-k8s01 Desktop]# tar -zvxf alltemp1.tar.gz --exclude alltemp.tar #除了alltemp.tar,其他的全部解压出来 ./0test/ ./1test/ ./2test/ ./3test/ ./4test/ ./5test/ ./6test/ ./7test/ ./8test/ ./9test/ ./alex.txt ./cesh1.txt ./ceshi1.txt ./ceshi.xt ./mjj.txt ./test.sh ./test.txt
gzip命令
要说tar命令是个纸箱子用于打包,gzip命令就是压缩机器
gzip通过压缩算法lempel-ziv算法(lz77)将文件压缩为较小文件,节省60%以上的存储空间,以及网络传输速率
gzip无法压缩文件夹,必须先tar对文件夹打包后,才可以gzip压缩
gzip (选项) (参数)
-a或者--ascii: 使用ASCII文字模式;
-c或--stdout或--to-stdout 把解压后的文件输出到标准输出设备
-d或--decompress或----uncompress: 解开压缩文件;
-f或--force:强行压缩文件。不理会文件名称或硬链接是否存在以及该文件是否为符号连接
-h或--help: 在线帮助
-l或--list:列出压缩文件的相关信息
-L或--license: 显示版本与版权信息;
-n或--no-name: 压缩文件时,不保存原来的文件名称及时间戳记;
-N或--name: 压缩文件时,保存原来的文件名称及时间戳记;
-q或--quiet: 不显示警告信息
-r或--recursive: 递归处理,将指定目录下的所有文件及子目录一并处理;
-S或<压缩字尾字符串>或----suffix<压缩字尾字符串>: 更改压缩字尾字符串;
-t或--test: 测试压缩文件是否正确无误;
-v或--verbose: 显示指令执行过程;
-V或--version: 显示版本信息;
-<压缩效率>:压缩效率是一个介于1-9的数值,预设值为"6",指定愈大的数值,压缩效率就会愈高
--best: 此参数的效果和指定"-9"参数相同
--fast: 此参数的效果和指定"-1"参数相同
案例
#压缩目录中每一个html文件为.gz,文件夹无法压缩,必须先tar打包
gzip *.html #gzip压缩,解压都会删除源文件
1.压缩所有.txt文件
[root@timy-test-k8s01 alltemp]# gzip ./*.txt
2.列出压缩文件中信息
[root@timy-test-k8s01 alltemp]# gzip -l *.gzcompressed uncompressed ratio uncompressed_name46 17 -11.8% alex.txt44 14 -14.3% cesh1.txt66 39 5.1% ceshi1.txt42 14 -14.3% mjj.txt72 43 -4.7% test.txt270 127 -91.3% (totals)
zip命令
zip命令:是一个应用广泛的跨平台的压缩工具,压缩文件的后缀为zip文件,还可以压缩文件夹
语法:
zip 压缩文件名 要压缩的内容
-A 自动解压文件
-c 给压缩文件加注释
-d 删除文件
-F 修复损坏文件
-k 兼容DOS
-m 压缩完毕后,删除源文件
-q 运行时不显示信息处理信息
-r 处理指定目录和指定目录下的使用子目录
-v 显示信息的处理信息
-x "文件列表"压缩时排除文件列表中的指定文件
-y 保留符号链接
-b<目录> 指定压缩到的目录
-i<格式> 匹配格式进行压缩
-L 显示版权信息
-t<日期> 指定压缩文件的日期
-<压缩率> 指定压缩率
案例
#压缩当前目录下所有内容为alltemp2.zip文件
[root@timy-test-k8s01 alltemp]# zip alltemp2.zip ./*
#压缩多个文件夹
[root@timy-test-k8s01 alltemp]# zip -r data.zip ./data ./data2
unzip命令用于解压
参数
-l 显示压缩文件内所包含的文件
-d<目录> 指定文件解压缩后所要存储的目录
tar、gzip、zip压缩命令相关推荐
- linux tar zcxf,tar/gzip/zip文件打包、压缩命令
一.tar打包备份工具 1.命令功能 tar 将多个文件或目录打包在一起,可用通过调用gzip或zip实现压缩.解压的命令:tar不仅可以多多个文件进行打包,还可以对多个文件打包后进行压缩. 2.语法 ...
- 压缩加压 linux 命令,linux下tar加压、压缩命令
linux下tar加压.压缩命令 参数: -c :建立一个压缩文件的参数指令(create 的意思): -x :解开一个压缩文件的参数指令! -t :查看 tarfile 里面的文件! 注意:在参数下 ...
- linux系统zip压缩命令,linux zip 压缩命令
linux zip命令 的基本用法是: zip [参数] [打包后的文件名] [打包的目录路径] linux zip命令 参数列表: -a 将文件转成ASCII模式 -F 尝 ...
- python压缩文件操作_Python tar、zip压缩文件操作方法
python语言源码练习,tar.zip压缩文件操作方法参考示例. import os import threading, zipfile import tarfile class AsyncZip( ...
- linux命令zip如何使用,linux zip压缩命令如何使用
linux zip压缩命令的使用方法:1.使用zip打包文件夹,代码为[zip -r -q -o pack.zip mark/]:2.使用[-e]参数可以创建加密压缩包,代码为[zip -r -e o ...
- Linux 压缩类命令 (tar gzip zip unzip compress uncompress zcat zdiff zless zgrep zipgrep)
文章目录 写在开头的话 Linux 压缩命令 00. tar 命令 0.1 tar 命令演示 0.2 tar 命令注意事项 01. gzip 压缩或者解压缩 1.1 命令说明 1.2 使用演示 02. ...
- tar,zip压缩命令
压缩解压 tar tar这个命令并没有压缩的功能,它只是一个打包的命令,但是在tar命令中增加一个选项(-z)可以调用gzip实现了一个压缩的功能,实行一个先打包后压缩的过程. 文件压缩解压:bzip ...
- Linux 命令行——gzip、gunzip、bzip、bunzip、tar、zip等命令
备份和归档 1.备份和归档 2.文件压缩(compression)程序 3. 归档(Archiving)程序 本文摘录自 Linux 命令行 1.备份和归档 计算机系统管理员的一个主要任务就是保护计算 ...
- tar, gzip, zip使用总结
一.命令复杂度 tar参数最多最复杂 使用tar压缩文件夹 tar -zcvf test.tar.gz ./test/ 该命令表示压缩当前文件夹下的文件夹test,压缩后缀名为test.tar.gz ...
最新文章
- C++链式队列基本操作
- nebula的nGQL语句可以为属性添加类似list的数字类型吗
- 【EF学习笔记09】----------使用 EntityState 枚举标记实体状态,实现增删改查
- 在Ubuntu下成功搭建以太坊私有链挖矿并转账
- java jdbc 连接mysql数据库,Java 通过JDBC连接Mysql数据库
- windows下使用net-snmp实现agent扩展(四)
- HBase使用场景和成功案例 (转)
- TreeView节点的演练 c# 1614840318
- 微信“农场”偷偷上线!网友:偷菜还会远吗 QQ被抄麻了
- 深度学习数据驱动_模型驱动的物理层通信深度学习
- elasticsearch查询操作(使用marvel插件)
- linux内核 3.1,快更新:Linux新内核发布 支持USB3.1!
- Ubuntu[16.04/18.04/20.04] arm 下修改本地源 sources.list 为国内镜像
- 软件测试自学指南---从入门到精通
- 【有利可图网】PS实战系列:PS制作人像印章效果
- JAVA JNI调用科大讯飞离线语音合成Windows
- freeswitch通过 sip网关联系外部世界
- int数据超出范围的值变化
- VS Code格式化代码插件Beautify
- oracle数据库的认证考试