zoukankan      html  css  js  c++  java
  • Linux下的打包操作

    范例一:将整个 test 目录下的文件全部打包成为 test.tar
    [python@master ~]$ tar -cvf test.tar test/         ==仅打包,不压缩!
    test/
    test/a1
    test/a2
    test/z.txt
    [python@master ~]$ tar -zcvf test.tar.gz  test/   ==打包后,以 gzip 压缩
    test/
    test/a1
    test/a2
    test/z.txt
    [python@master ~]$ tar -jcvf test.tar.bz2  test/  ==打包后,以 bzip2 压缩
    test/
    test/a1
    test/a2
    test/z.txt
    # 特别注意,在参数 f 之后的文件档名是自己取的,我们习惯上都用 .tar 来作为辨识。
    # 如果加 z 参数,则以 .tar.gz 或 .tgz 来代表 gzip 压缩过的 tar file ~
    # 如果加 j 参数,则以 .tar.bz2 来作为附档名啊~
    drwxrwxr-x  2 python python    39 10月 25 11:40 test
    -rw-rw-r--  1 python python 10240 10月 25 11:41 test.tar
    -rw-rw-r--  1 python python   174 10月 25 11:44 test.tar.gz
    -rw-rw-r--  1 python python   181 10月 25 11:47 test.tar.bz2

    打包压缩节省空间很大
    范例二:查阅上述 tar 文件内有哪些文件?
    [python@master ~]$ tar -tvf test.tar
    drwxrwxr-x python/python     0 2018-10-25 11:40 test/
    -rw-rw-r-- python/python     0 2018-10-25 11:12 test/a1
    -rw-rw-r-- python/python     0 2018-10-25 11:12 test/a2
    -rw-rw-r-- python/python     0 2018-10-25 11:13 test/z.txt
    [python@master ~]$ tar -ztvf test.tar.gz
    drwxrwxr-x python/python     0 2018-10-25 11:40 test/
    -rw-rw-r-- python/python     0 2018-10-25 11:12 test/a1
    -rw-rw-r-- python/python     0 2018-10-25 11:12 test/a2
    -rw-rw-r-- python/python     0 2018-10-25 11:13 test/z.txt
    [python@master ~]$
    [python@master ~]$ tar -jtvf test.tar.bz2
    drwxrwxr-x python/python     0 2018-10-25 11:40 test/
    -rw-rw-r-- python/python     0 2018-10-25 11:12 test/a1
    -rw-rw-r-- python/python     0 2018-10-25 11:12 test/a2
    -rw-rw-r-- python/python     0 2018-10-25 11:13 test/z.txt

    范例三:将 tar 文件解压缩在 /home/python/tmp 底下
    方法一、
    [python@master ~]$ cd tmp
    [python@master tmp]$ tar -xvf /home/python/test.tar
    方法二、
    [python@master ~]$ tar -zxvf  test.tar.gz -C /home/python/tmp


    范例四:在 /tmp 底下,我只想要将 /home/python/test.tar.gz 内的 test/a1 解开而已
    [python@master ~]$ cd tmp
    [python@master tmp]$ tar -zxvf /home/python/test.tar.gz test/a1
    # 我可以透过 tar -ztvf 来查阅 tarfile 内的文件名称,如果单只要一个文件,


    范例五:将 /etc/ 内的所有文件备份下来,并且保存其权限!
    [root@linux ~]# tar -zxvpf /tmp/etc.tar.gz /etc
    # 这个 -p 的属性是很重要的,尤其是当您要保留原本文件的属性时!

    范例六:在 /home 当中,比 2005/06/01 新的文件才备份
    [root@linux ~]# tar -N '2005/06/01′ -zcvf home.tar.gz /home

    范例七:我要备份 /home, /etc ,但不要 /home/dmtsai
    [root@linux ~]# tar –exclude /home/dmtsai -zcvf myfile.tar.gz /home/* /etc


    各类打包解包类型
    .tar
      解包:tar xvf FileName.tar
      打包:tar cvf FileName.tar DirName
      (注:tar是打包,不是压缩!)
      ———————————————
      .gz
      解压1:gunzip FileName.gz
      解压2:gzip -d FileName.gz
      压缩:gzip FileName
      .tar.gz 和 .tgz
      解压:tar zxvf FileName.tar.gz
      压缩:tar zcvf FileName.tar.gz DirName
      ———————————————
      .bz2
      解压1:bzip2 -d FileName.bz2
      解压2:bunzip2 FileName.bz2
      压缩: bzip2 -z FileName
      .tar.bz2
      解压:tar jxvf FileName.tar.bz2 或tar –bzip xvf FileName.tar.bz2
      压缩:tar jcvf FileName.tar.bz2 DirName
      ———————————————
      .bz
      解压1:bzip2 -d FileName.bz
      解压2:bunzip2 FileName.bz
      压缩:未知
      .tar.bz
      解压:tar jxvf FileName.tar.bz
      压缩:未知
      ———————————————
      .Z
      解压:uncompress FileName.Z
      压缩:compress FileName
      .tar.Z
      解压:tar Zxvf FileName.tar.Z
      压缩:tar Zcvf FileName.tar.Z DirName
      ———————————————
      .zip
      解压:unzip FileName.zip
      压缩:zip FileName.zip DirName
      压缩一个目录使用 -r 参数,-r 递归。例: $ zip -r FileName.zip DirName
      ———————————————
      .rar
      解压:rar x FileName.rar
      压缩:rar a FileName.rar DirName


  • 相关阅读:
    OAuth 2.0之授权码模式
    Rest和Restful & http
    HTTP1.1协议中文版-RFC2616
    Linux中安装Python2.7
    CvMat、Mat、IplImage之间的转换详解及实例
    ROS Node/Topic/Message/Service的一些问题
    ROS的tf_tree相关
    机器人路径规划(包括行人检测及动态避障总结)(长期更新)
    相关博客链接(长期更新)
    关于视觉里程计以及VI融合的相关研究(长期更新)
  • 原文地址:https://www.cnblogs.com/hello-wei/p/9849821.html
Copyright © 2011-2022 走看看