在 Linux 中使用 C 将精确的统计参数从一个文件应用到另一个文件

发布于 2024-12-29 15:21:26 字数 128 浏览 3 评论 0原文

我想从一个文件获取统计参数,然后将其按原样应用到同一文件的副本(包括类型、路径、权限、大小等)。
原始文件将从该目录中消失很久,副本将取代他的位置,并且应该具有完全相同的属性。
在 Linux 中使用 C 语言如何实现这一点?

I would like get stat parameters from one file and later apply it as is, to a copy of the same file (Including type, path, permissions, size, etc.).
The original file will be long gone from this directory and the copy will take his place, and should get the same exact properties.
How could this be done using C in Linux?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

多情癖 2025-01-05 15:21:26

如果我正确理解你的问题,你不需要编写自己的程序来做到这一点。

如果您的文件驻留在同一台计算机上,您可以在 tar< 中保留和恢复时间和权限/code>档案。 p 选项处理权限,默认情况下会保留时间(atime 除外,但 --atime-preserve 可以解决这个问题)。

或者,如果您想从远程服务器恢复文件,可以使用 rsync-a 选项。

If I understand your question correctly, you don't need to write your own program to do that.

If your files reside on the same machine, you can preserve and restore times and permissions in tar archives. The p option handles permissions, and times are persisted by default (except atime, but --atime-preserve can work around that).

Alternatively, if you want to restore files from a remote server, you can use rsync with the -a option.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文