TAR 可以记录符号链接及其引用的文件/目录吗?
Tar 命令有一个 -h 标志来跟踪符号链接,而不是记录符号链接。是否可以同时拥有符号链接和它们在存档中所指向的内容?这可以在一次运行 TAR 命令时自动完成吗?
The Tar command has an -h flag to follow symbolic links instead of recording the symbolic links. Is it possible to have both the symbolic links and what they point to in the archive? Can this be done automatically in one run of the TAR command?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
确保符号链接及其指向的目录/文件都位于 tar 内容内。
例如,假设您有一个文件
work/mydir/myfile.txt
和一个指向该文件的符号链接work/mylink
(带有相对路径):当您存档时在
work
目录中,符号链接和文件都放在 tar 存档中:解压 tar 存档时,将在目标目录中创建文件和符号链接。
Make sure both the symbolic link and the directory/file it points to are inside the tar content.
For example, assume you have a file
work/mydir/myfile.txt
and a symbolic linkwork/mylink
which points to that file (with relative path):When you archive the
work
directory, both the symbolic link and the file are put inside the tar archive:When that tar archive will be extracted, the file and the symbolic link will be created in the target directory.
这是一个很老的问题,但最近我在使用 tar 命令时遇到了同样的问题。
我需要保留 clickhouse 配置和元数据目录,它看起来像一个具有混合内容的目录:有些是带有元数据的目录,有些是目录的符号链接,所以我也应该保留原始内容和符号链接。这个命令对我有用。
Quite old question, but recently I had the same issue with tar command.
I need to preserve clickhouse config and metadata dir, which looks like a directory with mixed content: some are dirs with metadata, some are symlinks to dirs, so I should preserve original content and symlinks as well. This command worked for me.