python - unix系统中的getmtime()和getctime()的区别 [英] Difference between python - getmtime() and getctime() in unix system

查看:34
本文介绍了python - unix系统中的getmtime()和getctime()的区别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以指定 unix 系统中 os.path.getmtime(path)os.path.getctime(path) 之间的区别是什么.根据 python 文档中的定义:

Can someone please specify what is the difference between os.path.getmtime(path) and os.path.getctime(path) in unix systems . As per the defnition in python docs:

os.path.getmtime(path)

返回上次修改路径的时间.返回值是一个数字给出自纪元以来的秒数(见时间模块).如果文件不存在或无法访问,则引发 os.error.

Return the time of last modification of path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise os.error if the file does not exist or is inaccessible.

os.path.getctime(path)

返回系统的 ctime,在某些系统(如 Unix)上是上次更改的时间,并且在其他人(如 Windows)上,是路径的创建时间.返回值是一个给出数字的数字自纪元以来的秒数(请参阅时间模块).提高 os.error 如果该文件不存在或无法访问.

Return the system’s ctime which, on some systems (like Unix) is the time of the last change, and, on others (like Windows), is the creation time for path. The return value is a number giving the number of seconds since the epoch (see the time module). Raise os.error if the file does not exist or is inaccessible.

这是否意味着它们在 unix/systems 中使用时是相同的东西?

Does that basically mean they are the same things when used in unix/systems?

#!/usr/bin/python
import os
print os.path.getmtime('File')
print os.path.getctime('FIle')

两个打印件都为我获取了相同的值.

Both the prints fetch me the same value.

我基本上是在寻找文件的最后创建日期,而不是最后修改日期.有没有办法在 unix 中实现相同的目标?

I am basically looking for last creation date for file , rather than last modification date. Is there a way to achieve the same in unix?

推荐答案

mtime 指的是上次更改文件内容的时间.这可以在 Unix 系统上以各种方式改变.通常,当您从备份中恢复文件时,mtime 会更改以指示在进行备份之前内容最后一次更改的时间.

The mtime refers to last time the file's contents were changed. This can be altered on unix systems in various ways. Often, when you restore files from backup, the mtime is altered to indicate the last time the contents were changed before the backup was made.

ctime 表示上次更改 inode 的时间.这是无法改变的.在上面带有备份的示例中,ctime 仍将反映文件恢复的时间.此外,当文件权限等更改时,ctime 也会更新.

The ctime indicates the last time the inode was altered. This cannot be changed. In the above example with the backup, the ctime will still reflect the time of file restoration. Additionally, ctime is updated when things like file permissions are changed.

不幸的是,通常无法找到文件创建的原始日期.这是底层文件系统的限制.我相信 ext4 文件系统已经为 inode 添加了创建日期,Apple 的 HFS 也支持它,但我不确定你会如何在 Python 中检索它.(C stat 函数和相应的 stat 命令应该会显示有关支持它的文件系统的信息.)

Unfortunately, there's usually no way to find the original date of file creation. This is a limitation of the underlying filesystem. I believe the ext4 filesystem has added creation date to the inode, and Apple's HFS also supports it, but I'm not sure how you'd go about retrieving it in Python. (The C stat function and the corresponding stat command should show you that information on filesystems that support it.)

这篇关于python - unix系统中的getmtime()和getctime()的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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