首页 > 其他分享 >tar

tar

时间:2023-01-24 16:24:27浏览次数:32  
标签:audit files tar -- etc plural

 

Operation mode:

  1. -A --catenate ---concatenate  追加模式, 不能是压缩的
    tar -A a.tar -vf b.tar

    追加a.tar到b.tar后面

  2. -c --create 创建模式, 目录默认递归, --no-recursion不对目录递归

     

    tar cf c.tar --no-recursion plural/ helm/   # plural, helm 均不递归
    tar cf c.tar --no-recursion plural --recursion helm   # plural不递归, helm递归

     

  3. -d --diff 
    tar --diff -f c.tar -C plural

     

  4. --delete delete from archive, The arguments supply names of the archive members to be removed, At least one argument must be given
    tar --delete helm/plural/Chart.yaml -f c.tar

     

  5. --append Append files to the end of an archive, Arguments have the same meaning as for -c
    tar --append calico.yaml -f plural.tar

     

  6. -t --list Arguments are optional, when given, they specify the names of the members to list
    tar tf plural.tar b.yaml   # 只列出b.yaml

     

  7. -x  Extract files from an archive, Arguments are optional, When given, they specify names of archive memeber to extracted
    tar 压缩默认使用相对路径, 进入对应目录后extract
    cd /media && tar xf /root/plural.tar

    extract单个文件, -C --directory参数无效

    tar xf /root/plural.tar calico.yaml   # 支持补全

     

  8. --show-defaults

  9. --usage

Options:

  1. --exclude
    tar cvf audit.tar --exclude='*.rules' --exclude='*.conf' /etc/audit

     

  2. --absolute-names  tarball不移除 /, extract时移除
    tar cvf b.tar --exclude='*.rules' /etc/audit --absolute-names

    extract时保持 /, 会覆盖全局文件

    tar xf plugral.tar --absolute-names

    --keep-old-files      Don't replace existing files when extracting 报错
    --skip-old-files        Don't replace existing files when extracting,  silently skip over them 不报错

  3. --mode --owner --group
    tar cvf plural.tar --mode 7777 --owner bin --group adm /etc/audit

     

  4. -m  Don't extract file modified time 默认extracted出来的文件和archive的modified time相同, -m会使modified time修改成当前时间

  5. -p preserve-permissions, root默认有此选项, 普通用户需手动添加, 否则提取的文件权限和archive不同
  6. --same-owner        Try extracting files with the same ownership as exists in the archive (default for superuser).
  7. --strip-components Strip NUMBER leading components from file names on extraction 只会提取components>NUMBER的文件

  8. --files-from Get names to extract or create from FILE

 

Usage:

  1. 备份/etc/audit
    tar cvf - /etc/audit | tar xvf - -C /media

    备份到远端机器

    tar cvf - /etc/audit | ssh vandal-2 'tar xvf - -C /media'

     

  2. 打包隐藏文件
    tar cvf - `find . -print` > backup.tar

     

  3. 只打包/etc/audit下 *.rules *.conf
    find /etc/audit -name '*.rules' -o -name '*.conf' > list
    tar cvzf plural.tar.gz /etc/audit --files-from list
    
    
    find /etc/audit -name '*.rules' -o -name '*.conf' | tar cvzf plural.tar.gz --files-from -

     

标签:audit,files,tar,--,etc,plural
From: https://www.cnblogs.com/dissipate/p/17066141.html

相关文章