Linux 有没有办法知道ubuntu中文件的创建时间?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3813541/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-04 23:18:48  来源:igfitidea点击:

Is there a way to know the creation time of a file in ubuntu?

linuxubuntufilesystems

提问by fenec

i am using ubuntu and want to know the creation time of a file even when it gets modified or accessed ?

我正在使用 ubuntu 并且想知道文件的创建时间,即使它被修改或访问?

采纳答案by Thariama

Unfortunately Unix does not store the creation time of a file.

不幸的是,Unix 不存储文件的创建时间。

All you are able to get using statis

使用stat所能获得的只是

  1. time of last access
  2. time of last modification
  3. time of last status change
  1. 上次访问时间
  2. 最后修改时间
  3. 上次状态改变的时间

Note:When using filesystem type ext4crtimeis available!

注意:当使用文件系统类型ext4 crtime 时可用!

回答by Matt Joiner

The closest attribute available is the "change time", also known as ctime. This is updated for various system calls, any that modify the inode, rather than the data it contains.

最接近的可用属性是“更改时间”,也称为ctime。这是为各种系统调用更新的,任何修改 inode 的系统调用,而不是它包含的数据。

matt@stanley:~$ stat -c %z .bashrc 
2010-08-17 11:53:56.865431072 +1000

Links

链接

回答by MSalters

According to http://en.wikipedia.org/wiki/Comparison_of_file_systems, this is available for ext4, btfrs, FAT, NTFS, and UDF filesystems, plus some others you're unlikely to encounter. It's not available on ext2 or ext3, probably the most common file system formats in Ubuntu.

根据http://en.wikipedia.org/wiki/Comparison_of_file_systems,这适用于 ext4、btfrs、FAT、NTFS 和 UDF 文件系统,以及您不太可能遇到的其他一些文件系统。它在 ext2 或 ext3 上不可用,这可能是 Ubuntu 中最常见的文件系统格式。

You'll need a kernel patch, though: http://lwn.net/Articles/394391/. Apparently this is because Linus rejected creation time attribute on the grounds that somebody called it an "otime" and somebody else called it a "btime", and therefore the idea must be useless.

不过,您需要一个内核补丁:http: //lwn.net/Articles/394391/。显然这是因为 Linus 拒绝了创建时间属性,理由是有人称其为“otime”,而其他人称其为“btime”,因此这个想法一定是无用的。

回答by fenec

guys i just finished writing this script this script to find the creation date of a file using perl:

伙计们,我刚刚完成了这个脚本的编写,这个脚本是为了使用 perl 查找文件的创建日期:

use File::stat;
if (  scalar( @ARGV ) == 0 ) {
 die("type  a file  name  ex:perl filestat.pl <filename>");    
}
my $filename =  $ARGV[0] ;
my @info = stat($filename);
print "Creation time :",scalar localtime stat($filename)->ctime;
print "\n";

回答by Attila Fulop

This little script can get the creation date for ext4:

这个小脚本可以获取 ext4 的创建日期:

#!/bin/sh

fn=`realpath `
echo -n "Querying creation time of ..."
sudo debugfs -R "stat $fn" /dev/sda4|grep crtime

I named it fcrtimeand put it in my ~/binfolder. So in any folder I can use the command like: fcrtime example.odp

我给它命名fcrtime并将它放在我的~/bin文件夹中。所以在任何文件夹中我都可以使用如下命令:fcrtime example.odp

Example output:

示例输出:

crtime: 0x5163e3f0:12d6c108 -- Tue Apr 9 12:48:32 2013

crtime: 0x5163e3f0:12d6c108 -- Tue Apr 9 12:48:32 2013

Compared to stat-ing the same file:

与 stat-ing 相同的文件相比:

  File: `example.odp'
  Size: 54962       Blocks: 112        IO Block: 4096   regular file
Device: 804h/2052d  Inode: 11019246    Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1000/   fulop)   Gid: ( 1000/   fulop)
Access: 2013-04-09 13:20:05.263016001 +0300
Modify: 2013-04-09 13:20:05.227016001 +0300
Change: 2013-04-09 13:20:05.227016001 +0300
 Birth: -

NOTES

笔记

  1. realpathis usually not installed by default. In Ubuntu eg. install it with sudo apt-get install realpath
  2. Replace /dev/sda4if necessary with the one you get from mount|grep ext4
  1. realpath默认情况下通常不安装。在 Ubuntu 例如。安装它sudo apt-get install realpath
  2. /dev/sda4如有必要,请替换为您从中获得的mount|grep ext4

回答by Franklin Piat

Creation time, is known as file Birth timeand is supported on some filesystem, with some kernels only. The command would be Mohsen Pahlevanzadehanswer:

创建时间,称为文件出生时间在某些文件系统上受支持,只有某些内核。命令将是Mohsen Pahlevanzadeh 的回答:

stat --printf='%w' yourfile   #human readable

stat --printf='%W' yourfile   #seconds from Epoch , 0 if unknown

Note: this question is a duplicate of How to find creation date of file?. Also, make sure to read this question What file systems on Linux store the creation time?.

注意:此问题与如何查找文件的创建日期?. 另外,请务必阅读这个问题Linux 上的哪些文件系统存储创建时间?.