i am using ubuntu and want to know the creation time of a file even when it gets modified or accessed ?
我正在使用ubuntu并想知道文件的创建时间,即使它被修改或访问?
7 个解决方案
#1
19
Unfortunately Unix does not store the creation time of a file.
不幸的是,Unix不存储文件的创建时间。
All you are able to get using stat is
你能用stat获得的就是
- time of last access
- 上次访问的时间
- time of last modification
- 最后修改的时间
- time of last status change
- 最后一次状态变化的时间
Note: When using filesystem type ext4 crtime is available!
注意:使用文件系统类型时,ext4 crtime可用!
#2
3
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
#3
3
This little script can get the creation date for ext4:
这个小脚本可以获得ext4的创建日期:
#!/bin/sh
fn=`realpath $1`
echo -n "Querying creation time of $1..."
sudo debugfs -R "stat $fn" /dev/sda4|grep crtime
I named it fcrtime
and put it in my ~/bin
folder. 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:
与统计同一文件相比:
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
笔记
-
realpath
is usually not installed by default. In Ubuntu eg. install it withsudo apt-get install realpath
- 默认情况下通常不安装realpath。在Ubuntu例如。用sudo apt-get install realpath安装它
- Replace
/dev/sda4
if necessary with the one you get frommount|grep ext4
- 如果需要,将/ dev / sda4替换为mount | grep ext4
#4
1
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”,因此这个想法必须毫无用处。
#5
1
Creation time, is known as file Birth time and is supported on some filesystem, with some kernels only. The command would be Mohsen Pahlevanzadeh answer:
创建时间称为文件生成时间,并且在某些文件系统上受支持,仅包含一些内核。命令将是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上的哪些文件系统存储创建时间?
#6
-3
Yup - stat(): http://manpages.ubuntu.com/manpages/hardy/man2/stat.2.html
是的 - stat():http://manpages.ubuntu.com/manpages/hardy/man2/stat.2.html
#7
-3
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";
#1
19
Unfortunately Unix does not store the creation time of a file.
不幸的是,Unix不存储文件的创建时间。
All you are able to get using stat is
你能用stat获得的就是
- time of last access
- 上次访问的时间
- time of last modification
- 最后修改的时间
- time of last status change
- 最后一次状态变化的时间
Note: When using filesystem type ext4 crtime is available!
注意:使用文件系统类型时,ext4 crtime可用!
#2
3
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
#3
3
This little script can get the creation date for ext4:
这个小脚本可以获得ext4的创建日期:
#!/bin/sh
fn=`realpath $1`
echo -n "Querying creation time of $1..."
sudo debugfs -R "stat $fn" /dev/sda4|grep crtime
I named it fcrtime
and put it in my ~/bin
folder. 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:
与统计同一文件相比:
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
笔记
-
realpath
is usually not installed by default. In Ubuntu eg. install it withsudo apt-get install realpath
- 默认情况下通常不安装realpath。在Ubuntu例如。用sudo apt-get install realpath安装它
- Replace
/dev/sda4
if necessary with the one you get frommount|grep ext4
- 如果需要,将/ dev / sda4替换为mount | grep ext4
#4
1
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”,因此这个想法必须毫无用处。
#5
1
Creation time, is known as file Birth time and is supported on some filesystem, with some kernels only. The command would be Mohsen Pahlevanzadeh answer:
创建时间称为文件生成时间,并且在某些文件系统上受支持,仅包含一些内核。命令将是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上的哪些文件系统存储创建时间?
#6
-3
Yup - stat(): http://manpages.ubuntu.com/manpages/hardy/man2/stat.2.html
是的 - stat():http://manpages.ubuntu.com/manpages/hardy/man2/stat.2.html
#7
-3
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";