防止父目录被焦油化
基本上我只想压缩目录中的所有文件,但不想获取存档中的所有父目录。
我已经尝试过-C,但我想我没有正确使用它。
tar -cjf archive.tar.bz2 -C /var/some/log/path ./*
这会导致 tar 尝试添加 CWD 中的所有文件。使用完整路径作为最后一个参数不会阻止添加目录。
看起来很简单,但无法弄清楚。不知何故, tar 不会将 ./* 压缩为相对于 -C 的目录,尽管它应该更改为该目录。
帮助表示赞赏。
Basically I just want to tar all the files in a directory, but not get all the parent directories in the archive.
I've tried -C, but I guess I'm not using it right.
tar -cjf archive.tar.bz2 -C /var/some/log/path ./*
This results in tar trying to add all the files in the CWD. Using the full path as last argument doesn't prevent the dirs from being added.
Seems simple enough, but can't figure it out. Somehow tar does not tar ./* as being relative to -C, although it should change to that dir.
Help appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
包含父目录 (
/var/some/log
),因为执行./ 时包含
/var/some/log/path/..
*。尝试只进行测试运行:
The parent directory (
/var/some/log
) is included, since/var/some/log/path/..
is included when you do./*
. Try just doingTest run:
有一种更简单的方法可以做到这一点:
cd
到您希望位于顶层的目录,即..cd /var/lib/mysql
从 tar 命令中删除父目录
/var/lib/mysql/DATABASE_NAME
变为DATABASE_NAME
更多详细信息可以在 此博客文章。
There's a much easier way to do this:
cd
down to the directory you wish to be top level, i.e...cd /var/lib/mysql
Remove parent directories from your tar command
/var/lib/mysql/DATABASE_NAME
becomes justDATABASE_NAME
More details can be found in this blog writeup.