如何修改“上次状态更改” Unix 中文件的 (ctime) 属性?
我知道有一种方法可以同时修改“修改”(mtime) 和“上次访问”(atime)使用“touch”命令获取 Unix 系统中给定文件的时间属性。 但我想知道是否也存在修改“上次状态更改”(ctime) 属性的方法?
I know there's a way to modify both 'modification' (mtime) and 'last access' (atime) time properties of a given file in Unix System by using "touch" command.
But I'm wondering whether there exists a way to modify "Last status change" (ctime) property, as well?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
ctime 是文件 inode 上次更改的时间。 mtime 是文件内容最后一次更改的时间。要修改 ctime,您必须对 inode 执行某些操作,例如对文件执行 chmod 或 chown。
更改文件的内容必然也会更新 ctime,因为 atime/mtime/ctime 值存储在 inode 中。修改 mtime 意味着 ctime 也会更新。
ctime is the time the file's inode was last changed. mtime is the last time the file's CONTENTS were changed. To modify ctime, you'll have to do something to the inode, such as doing a chmod or chown on the file.
Changing the file's contents will necessarily also update ctime, as the atime/mtime/ctime values are stored in the inode. Modifying mtime means ctime also gets updated.
使用“utime”系统调用。如果您查找其联机帮助页,还会发现具有微秒分辨率的 utimes,以及具有纳秒分辨率的 utimensat 的链接。
对 inode 的任何更改(例如对时间的更改)都会将“ctime”设置为当前时间,因此将 ctime 设置为过去的时间会立即将其翻转回当前时间。他们很早就意识到了这一点,所以没有设置ctime的接口。
这也有助于维护系统的完整性:你可以乱搞 atime 和 mtime,但 ctime 是由系统维护的。
(例如,即使您删除了他的 /etc/passwd 条目,黑客也可能会修改您的 /bin/login 以允许他访问。由于文件上的异常 mtime,您发现了他。下次他将 mtime 更改回系统时已安装,但他无法隐藏 ctime!)。
Use the "utime" system call. If you look up its manpage there will also be utimes, having microsecond resolution, and a link to utimensat that has nanosecond resolution.
Any change to the inode like such a change to the times will set the "ctime" to the current time, so setting ctime to something in the past would immediately flip it back to the present. They realized this a long time ago, so there is no interface to set ctime.
This also helps maintain the integrity of the system: you can mess around with atime and mtime, but ctime is maintained by the system.
(A hacker might for example modify your /bin/login to allow him access even if you remove his /etc/passwd entry. You spot him because of the unusual mtime on the file. Next time he changes the mtime back to when the system was installed, but he can't hide the ctime!).
ln 命令将 ctime 设置为当前时间,因为使用次数发生了更改。我将它用于以下名为 /usr/local/bin/ctouch 的脚本:
错误管理有点差。
The
ln
command sets the ctime to the current time, because the usage number is changed. I used it for the following script named /usr/local/bin/ctouch:The error management is a little bit poor.