在 Linux 中使用 C 将精确的统计参数从一个文件应用到另一个文件
我想从一个文件获取统计参数,然后将其按原样应用到同一文件的副本(包括类型、路径、权限、大小等)。
原始文件将从该目录中消失很久,副本将取代他的位置,并且应该具有完全相同的属性。
在 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我正确理解你的问题,你不需要编写自己的程序来做到这一点。
如果您的文件驻留在同一台计算机上,您可以在
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. Thep
option handles permissions, and times are persisted by default (exceptatime
, 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.