无论如何,是否可以使用Python或任何语言手动修改统计信息,例如mtime或ctime? [英] Is there anyway to modify stat information like mtime or ctime manually in Python or any language at all?

查看:85
本文介绍了无论如何,是否可以使用Python或任何语言手动修改统计信息,例如mtime或ctime?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试以下代码:

os.stat(path_name)[stat.ST_CTIME] = ctime

但是,这会出现以下错误:

However, this gives the following error:

exceptions.TypeError: 'posix.stat_result' object does not support item assignment

反正还有修改ctime吗?

Is there anyway to modify ctime?

谢谢!

推荐答案

os.utime(filename, timetuple)可用于设置文件的atime和mtime.据我所知,没有办法不使用诸如时钟或文件系统直接版本之类的黑客手段而修改用户名中的ctime(我不建议这样做),并且对于任何编程语言(Python)都是如此. ,Perl,C,C ++ ...):它是内部操作系统的东西,您不想碰它.

os.utime(filename, timetuple) can be used to set the atime and mtime of a file. As far as I know there is no way to modify the ctime from userland without resorting to hacks such as playing with the clock or direct edition of the filesystem (which I really do not recommend), and this is true for any programming language (Python, Perl, C, C++...) : it's internal OS stuff, and you don't want to touch it.

例如,参见touch命令的文档(http://www.delorie.com/gnu/docs/fileutils/fileutils_54.html):

See for example in the documentation of the touch command (http://www.delorie.com/gnu/docs/fileutils/fileutils_54.html):

尽管touch提供了以下选项 改变两次-时代 最后访问和修改的- 一个文件,实际上有第三个 以及:inode更改时间.这 通常称为文件的 ctime.索引节点更改时间 表示文件的 元信息上次更改.一 常见的例子是 文件更改权限.改变中 权限无法访问 文件,因此atime不会更改,也不会 它会修改文件吗,所以mtime 不会改变.但是,关于 文件本身已更改,并且此 必须在某处注明.这是 ctime字段的工作.这是 必要的,例如 备份程序可以制作一个新副本 的文件,包括新的 权限值.另一操作 修改文件的ctime而不 重命名其他人.在 在任何情况下,不可能 正常操作,供用户 将ctime字段更改为 用户指定的值.

Although touch provides options for changing two of the times -- the times of last access and modification -- of a file, there is actually a third one as well: the inode change time. This is often referred to as a file's ctime. The inode change time represents the time when the file's meta-information last changed. One common example of this is when the permissions of a file change. Changing the permissions doesn't access the file, so the atime doesn't change, nor does it modify the file, so the mtime doesn't change. Yet, something about the file itself has changed, and this must be noted somewhere. This is the job of the ctime field. This is necessary, so that, for example, a backup program can make a fresh copy of the file, including the new permissions value. Another operation that modifies a file's ctime without affecting the others is renaming. In any case, it is not possible, in normal operations, for a user to change the ctime field to a user-specified value.

这篇关于无论如何,是否可以使用Python或任何语言手动修改统计信息,例如mtime或ctime?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆