摘要:本文主要向大家介绍了Linux运维知识之Linux中zip和tar处理软链接的差异与选择,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。
本文主要向大家介绍了Linux运维知识之Linux中zip和tar处理软链接的差异与选择,通过具体的内容向大家展现,希望对大家学习Linux运维知识有所帮助。
系统环境
cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
getenforce
Disabled
安装zip,unzip
#直接yum安装
yum install -y zip unzip
创建实验文件
#cd到tmp目录下
cd /tmp
#创建目录及文件
mkdir test
echo "this is a test file" > test.txt
cd ./test
echo "datagrand.com" > datagrand
#创建软链接文件
##这里的软连接文件,我创建两种,一种源文件是在tmp目录下的,一种源文件是在/tmp/test目录下。具体创建流程如下:
ln -s /etc/passwd /tmp/passwd
ln -s /tmp/test/datagrand /tmp/datagrand
#查看实验用的所有文件
pwd
/tmp
ls -l
lrwxrwxrwx 1 root root 19 5月 16 18:33 datagrand -> /tmp/test/datagrand
lrwxrwxrwx 1 root root 11 5月 16 18:31 passwd -> /etc/passwd
drwxr-xr-x 2 root root 23 5月 16 18:33 test
-rw-r--r-- 1 root root 20 5月 16 18:30 test.txt
zip实战
#当前路径
pwd
/
#打包详情
zip -r tmp.zip ./tmp
adding: tmp/ (stored 0%)
adding: tmp/test/ (stored 0%)
adding: tmp/test/datagrand (stored 0%)
adding: tmp/test.txt (stored 0%)
adding: tmp/passwd (deflated 60%)
adding: tmp/datagrand (stored 0%)
#解包
unzip tmp.zip
ll
总用量 4
drwxrwxrwx 9 root root 232 5月 16 19:00 tmp
-rw-r--r-- 1 root root 3219 5月 16 19:00 tmp.zip
cd ./tmp
-rw-r--r-- 1 root root 14 5月 16 18:33 datagrand
-rw-r--r-- 1 root root 1454 4月 20 18:58 passwd
drwxr-xr-x 2 root root 23 5月 16 18:33 test
-rw-r--r-- 1 root root 20 5月 16 18:30 test.txt
#说明
(1)使用unzip,原打包文件还是存在的,如上例tmp.zip。
直接使用zip打包,软连接会消失,原来的软链接文件被源文件的内容所代替,相当于原来的软链接变成了硬链接。
#使用参数-y
##为使zip能够保留软链接
zip -ry tmp2.zip tmp
unzip tmp2.zip
ll
lrwxrwxrwx 1 root root 19 5月 16 19:22 datagrand -> /tmp/test/datagrand
lrwxrwxrwx 1 root root 11 5月 16 19:22 passwd -> /etc/passwd
drwxr-xr-x 2 root root 23 5月 16 18:33 test
-rw-r--r-- 1 root root 20 5月 16 18:30 test.txt
#说明
zip使用参数-y,可以保留原文件中的软链接。
tar实战
#cd到tmp目录
cd /tmp
#tar打包压缩
tar -zcvf tmp3.tgz .
#解压缩
tar zxvf tmp3.tgz
#查看解压后的文件
lrwxrwxrwx 1 root root 19 5月 16 18:33 datagrand -> /tmp/test/datagrand
lrwxrwxrwx 1 root root 11 5月 16 18:31 passwd -> /etc/passwd
drwxr-xr-x 2 root root 23 5月 16 18:33 test
-rw-r--r-- 1 root root 20 5月 16 18:30 test.txt
-rw-r--r-- 1 root root 478 5月 16 19:28 tmp3.tgz
#说明
(1)tar解压缩后,原压缩文件还是存在的,如上所示。
(2)使用tar打包压缩可以保留原文件中的软链接。
总结鉴于上面的测试,我们可以看出,两者均是可以保留原文件中的软链接的,可根据自己的喜好来使用。
本文由职坐标整理并发布,希望对同学们有所帮助。了解更多详情请关注系统运维Linux频道!
您输入的评论内容中包含违禁敏感词
我知道了
请输入正确的手机号码
请输入正确的验证码
您今天的短信下发次数太多了,明天再试试吧!
我们会在第一时间安排职业规划师联系您!
您也可以联系我们的职业规划师咨询:
版权所有 职坐标-一站式IT培训就业服务领导者 沪ICP备13042190号-4
上海海同信息科技有限公司 Copyright ©2015 www.zhizuobiao.com,All Rights Reserved.
沪公网安备 31011502005948号