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

时间:2010-09-28 13:59:33

标签: linux ubuntu filesystems

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

7 个答案:

答案 0 :(得分:22)

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

您可以使用 stat 获取所有内容

  1. 上次访问的时间
  2. 上次修改时间
  3. 上次状态更改的时间
  4. 注意:使用文件系统类型 ext4 crtime时可用!

答案 1 :(得分:3)

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

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

链接

答案 2 :(得分:3)

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

#!/bin/sh

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

我将其命名为fcrtime并将其放入我的~/bin文件夹中。 因此,在任何文件夹中,我都可以使用如下命令:fcrtime example.odp

示例输出:

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

与统计同一档案相比:

  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: -

备注

    默认情况下,通常不会安装
  1. realpath。在Ubuntu例如。使用sudo apt-get install realpath
  2. 安装它
  3. 如有必要,请将/dev/sda4替换为mount|grep ext4

答案 3 :(得分:1)

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

但是你需要一个内核补丁:http://lwn.net/Articles/394391/。显然这是因为Linus拒绝了创作时间属性,理由是有人称之为“otime”而其他人称之为“btime”,因此这个想法必须毫无用处。

答案 4 :(得分:1)

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

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

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

注意:此问题与How to find creation date of file?重复。另外,请务必阅读此问题What file systems on Linux store the creation time?

答案 5 :(得分:-3)

答案 6 :(得分:-3)

我刚刚写完这个脚本这个脚本,用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";