Operation mode:
- -A --catenate ---concatenate 追加模式, 不能是压缩的
tar -A a.tar -vf b.tar
追加a.tar到b.tar后面
- -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递归
- -d --diff
tar --diff -f c.tar -C plural
- --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
- --append Append files to the end of an archive, Arguments have the same meaning as for -c
tar --append calico.yaml -f plural.tar
- -t --list Arguments are optional, when given, they specify the names of the members to list
tar tf plural.tar b.yaml # 只列出b.yaml
- -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 # 支持补全
- --show-defaults
- --usage
Options:
- --exclude
tar cvf audit.tar --exclude='*.rules' --exclude='*.conf' /etc/audit
- --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 不报错 - --mode --owner --group
tar cvf plural.tar --mode 7777 --owner bin --group adm /etc/audit
- -m Don't extract file modified time 默认extracted出来的文件和archive的modified time相同, -m会使modified time修改成当前时间
- -p preserve-permissions, root默认有此选项, 普通用户需手动添加, 否则提取的文件权限和archive不同
- --same-owner Try extracting files with the same ownership as exists in the archive (default for superuser).
- --strip-components Strip NUMBER leading components from file names on extraction 只会提取components>NUMBER的文件
- --files-from Get names to extract or create from FILE
Usage:
- 备份/etc/audit
tar cvf - /etc/audit | tar xvf - -C /media
备份到远端机器
tar cvf - /etc/audit | ssh vandal-2 'tar xvf - -C /media'
- 打包隐藏文件
tar cvf - `find . -print` > backup.tar
- 只打包/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 -