• tar 使用总结


    今天需要备份数据,使用tar命令,总结一下。

    压缩命令:

    tar -zvvf ticket-data-intgration.tar.gz ticket-data-intgration

    压缩但是不包含某个文件夹

    tar  --exclude /home/q/ticket-data-intgration/log --exclude /home/q/ticket-data-intgration/cache -zvvf ticket-data-intgration.tar.gz /home/q/ticket-data-intgration

    查看tar包的文件

    tar -tzvf ticket-data-intgration.tar.gz

    错误:/bin/tar: Removing leading `/' from member names

    首先应该明确:linux系统中,使用tar对文件打包时,一般不建议使用绝对路径。使用绝对路径打包时如果不指定相应的参数,tar会产生一句警告信息:”tar: Removing leading `/’ from member names”,并且实际产生的压缩包会将绝对路径转化为相对路径。比如:

    root@queen ~ # tar -czvf robin.tar.gz /home/robin
    tar: Removing leading `/' from member names
    /home/robin/
    /home/robin/file1
    /home/robin/file2
    /home/robin/file3
    root@queen ~ # tar -tzvf robin.tar.gz
    drwxr-xr-x robin/root        0 2009-11-10 18:51:31 home/robin/
    -rw-r--r-- robin/root        0 2009-11-10 18:51:28 home/robin/file1
    -rw-r--r-- robin/root        0 2009-11-10 18:51:30 home/robin/file2
    -rw-r--r-- robin/root        0 2009-11-10 18:51:31 home/robin/file3
    root@queen ~ #

    这样的一个压缩包,如果我们再去解开,就会当前目录(也即此例中的“~”)下再新建出“./home/robin/” 两级目录。对于这样的压缩包,解压方法是使用参数 “-C”指解压的目录为根目录(“/”):tar -xzvf robin.tar.gz -C /

    更为方便的方法是在打包和解开的时候都使用参数 -P

    root@queen ~ # tar -czvPf robin.tar.gz /home/robin/
    /home/robin/
    /home/robin/file1
    /home/robin/file2
    /home/robin/file3
    root@queen ~ # tar tzvf robin.tar.gz
    drwxr-xr-x robin/root        0 2009-11-10 18:51:31 /home/robin/
    -rw-r--r-- robin/root        0 2009-11-10 18:51:28 /home/robin/file1
    -rw-r--r-- robin/root        0 2009-11-10 18:51:30 /home/robin/file2
    -rw-r--r-- robin/root        0 2009-11-10 18:51:31 /home/robin/file3
    root@queen ~ # tar -xzvPf robin.tar.gz
    /home/robin/
    /home/robin/file1
    /home/robin/file2
    /home/robin/file3
    root@queen ~ #

    注意:上面-P的大小写和位置都不能改变

  • 相关阅读:
    期权标的概率密度函数
    Girsanov Theorem
    拉马努金恒等式
    波动率的三类模型
    stack(栈) and heap(堆)
    covar of lognormal variables
    BS 相关的一些近似公式
    布朗运动的一些特殊性质
    排序算法
    Mac node.js
  • 原文地址:https://www.cnblogs.com/liqiu/p/3919749.html
Copyright © 2020-2023  润新知