使用.tarignore文件从tar存档中排除目录 [英] Exclude directories from tar archive with a .tarignore file

查看:81
本文介绍了使用.tarignore文件从tar存档中排除目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以与 .gitignore 类似的方式,是否有可能使子目录中的 .tarignore 文件在执行操作时使其从存档中排除

In a similar way to .gitignore, is it possible to do that a .tarignore file in a subdirectory makes it excluded from archive when doing

tar cfjvh backup.tar.bz2 .

(我知道 tar -exclude 参数,但这不是我想要的).

(I know the --exclude parameter of tar but here it's not what I want).

推荐答案

您可以做类似的事情

$ COPYFILE_DISABLE=true tar -c --exclude-from=.tarignore -vzf archiveName.tar.gz

明细:-

  • COPYFILE_DISABLE = true 的原因是要确保以 ._ 开头的文件不包含在所创建的 .tar 文件中.如果经常执行 tar 操作,请启用它,将Mac上的 export COPYFILE_DISABLE = true 永久添加到〜/.bash_profile .
  • –exclude-from = .tarignore:忽略 .tarignore
  • 中列出的所有文件和文件夹
  • Reason for COPYFILE_DISABLE=trueis for making sure files starting with ._ are not included in the .tar file made. Enable it permanently adding export COPYFILE_DISABLE=true to ~/.bash_profile on your Mac if you frequently do tar operations.
  • –exclude-from=.tarignore: Ignore all files and folders listed in .tarignore

您可以在 .tarignore 中包含以下内容,这是我的

You can have the following content in your .tarignore, here is mine

$ cat .tarignore
.DS_Store
.git
.gitignore

这篇关于使用.tarignore文件从tar存档中排除目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆