[{"createTime":1735734952000,"id":1,"img":"hwy_ms_500_252.jpeg","link":"https://activity.huaweicloud.com/cps.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=V1g3MDY4NTY=&utm_medium=cps&utm_campaign=201905","name":"华为云秒杀","status":9,"txt":"华为云38元秒杀","type":1,"updateTime":1735747411000,"userId":3},{"createTime":1736173885000,"id":2,"img":"txy_480_300.png","link":"https://cloud.tencent.com/act/cps/redirect?redirect=1077&cps_key=edb15096bfff75effaaa8c8bb66138bd&from=console","name":"腾讯云秒杀","status":9,"txt":"腾讯云限量秒杀","type":1,"updateTime":1736173885000,"userId":3},{"createTime":1736177492000,"id":3,"img":"aly_251_140.png","link":"https://www.aliyun.com/minisite/goods?userCode=pwp8kmv3","memo":"","name":"阿里云","status":9,"txt":"阿里云2折起","type":1,"updateTime":1736177492000,"userId":3},{"createTime":1735660800000,"id":4,"img":"vultr_560_300.png","link":"https://www.vultr.com/?ref=9603742-8H","name":"Vultr","status":9,"txt":"Vultr送$100","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":5,"img":"jdy_663_320.jpg","link":"https://3.cn/2ay1-e5t","name":"京东云","status":9,"txt":"京东云特惠专区","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":6,"img":"new_ads.png","link":"https://www.iodraw.com/ads","name":"发布广告","status":9,"txt":"发布广告","type":1,"updateTime":1735660800000,"userId":3},{"createTime":1735660800000,"id":7,"img":"yun_910_50.png","link":"https://activity.huaweicloud.com/discount_area_v5/index.html?fromacct=261f35b6-af54-4511-a2ca-910fa15905d1&utm_source=aXhpYW95YW5nOA===&utm_medium=cps&utm_campaign=201905","name":"底部","status":9,"txt":"高性能云服务器2折起","type":2,"updateTime":1735660800000,"userId":3}]
tar 命令用于文件的打包或压缩,是最为常用的打包压缩命令,其语法格式如下:
tar [选项] 文件名.tar.gz 源文件 tar -czvf xxx.tar.gz source_file (tar -czvf 包名.tar.gz
源文件) #以tar.gz方式打包并gz方式压缩 tar -xzvf xxx.tar.gz -C path (tar -xzvf xxx.tar.gz -C
目标路径) #解压缩包
注意:使用tar命令,打包仅仅是打包xxx.tar,打包并压缩就是xxxx.tar.gz
,打包压缩的文件一定要指定文件格式,这样解包解压才好用对应的参数来解包解压缩,注意压缩包文件名和源文件位置不要颠倒了。
常用参数选项:
-c --create :创建新的归档文件,即打包,打包的意思就是说把一堆文件打包成一个文件 -v --verbose
:可视化,显示详细的tar处理的文件信息的过程 -f --file :要操作的文件名 -x --extract :解压文件 -z --gzip,
--gunzip, --ungzip :通过gzip 来进行归档压缩,如 tar -czvf etc.tar.gz /etc/,解压使用tar -zxvf
test.tar.gz -j --bzip2 :通过bzip2 来归档压缩文件,如 tar -jcvf test.tar.bz2 /etc/,解压使用tar
-jxvf test.tar.bz2 -J :使用xz压缩工具压缩成.xz文件,如tar -Jcvf test.tar.xz /etc/,解压使用tar
-Jxvf test.tar.xz -t --list :表示查看文件,查看文件中的文件内容 -C --directory=DIR
:解压文件至指定的目录,如果是解压到当前目录,可以不加-C
演示示例:
[root@Centos8 ~]# tar -cvf etc.tar /etc/ #仅仅是打包,并没有压缩 [root@Centos8 ~]# tar
-xvf etc.tar #解包 [root@Centos8 ~]# tar -xf etc.tar #解包,无输出 [root@Centos8 ~]#
tar -xf tomcat.tar.gz #习惯性直接xf参数解包,不管是tar还是tar.gz的都会自动解析 [root@Centos8 ~]# tar
-czvf etc.tar.gz /etc/ #打包并压缩/etc/目录,压缩包存放在当前目录,名字为etc.tar.gz [root@Centos8 ~]#
tar -xzvf etc.tar.gz -C /data/ #解压缩etc.tar.gz到指定目录,如果是解压到当前目录,可以不用加-C [
root@Centos8 ~]# tar -tvf etc.tar.gz #查看压缩包内容 [root@Centos8 ~]# tar -tf
etc.tar.gz #查看压缩包内容
我们更习惯使用gzip格式进行压缩,当然xz格式是压缩率最好的,压缩后文件大小也是最小的,但它的压缩时间也就长。