The difference and choice between zip and tar processing soft links in Linux

Source: Internet
Author: User

The difference and choice between zip and tar processing soft links in Linux

  1. System environment
    cat /etc/redhat-release CentOS Linux release 7.3.1611 (Core)getenforceDisabled
  2. Installing Zip,unzip
    #直接yum安装yum install -y zip unzip
  3. Create an experiment file
    #cd到tmp目录下cd /tmp
    #创建目录及文件mkdir testecho "this is a test file" > test.txtcd ./testecho "datagrand.com" > datagrand
    #创建软链接文件##这里的软连接文件,我创建两种,一种源文件是在tmp目录下的,一种源文件是在/tmp/test目录下。具体创建流程如下:ln -s /etc/passwd /tmp/passwdln -s /tmp/test/datagrand /tmp/datagrand
    #查看实验用的所有文件pwd/tmpls -llrwxrwxrwx 1 root root 19 5月  16 18:33 datagrand -> /tmp/test/datagrandlrwxrwxrwx 1 root root 11 5月  16 18:31 passwd -> /etc/passwddrwxr-xr-x 2 root root 23 5月  16 18:33 test-rw-r--r-- 1 root root 20 5月  16 18:30 test.txt
  4. Zip combat
    #当前路径pwd/
    #打包详情zip -r tmp.zip ./tmpadding: 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.zipll总用量 4drwxrwxrwx 9 root root  232 5月  16 19:00 tmp-rw-r--r-- 1 root root 3219 5月  16 19:00 tmp.zipcd  ./tmp-rw-r--r-- 1 root root   14 5月  16 18:33 datagrand-rw-r--r-- 1 root root 1454 4月  20 18:58 passwddrwxr-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 tmpunzip tmp2.ziplllrwxrwxrwx 1 root root 19 5月  16 19:22 datagrand -> /tmp/test/datagrandlrwxrwxrwx 1 root root 11 5月  16 19:22 passwd -> /etc/passwddrwxr-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,可以保留原文件中的软链接。
  5. Tar combat
    #cd到tmp目录cd /tmp
    #tar打包压缩tar -zcvf tmp3.tgz .
    #查看解压后的文件lrwxrwxrwx 1 root root  19 5月  16 18:33 datagrand -> /tmp/test/datagrandlrwxrwxrwx 1 root root  11 5月  16 18:31 passwd -> /etc/passwddrwxr-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打包压缩可以保留原文件中的软链接。
  6. Summarize
    In view of the above test, we can see that both can retain the original file of soft links, can be used according to their own preferences.

The difference and choice between zip and tar processing soft links in Linux

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.