我正在使用ubuntu并想知道文件的创建时间,即使它被修改或访问?
答案 0 :(得分:22)
答案 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: -
备注强>
realpath
。在Ubuntu例如。使用sudo apt-get install realpath
/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)
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";