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

发布于 2024-09-25 17:09:07 字数 43 浏览 3 评论 0原文

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

冷…雨湿花 2024-10-02 17:09:07

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

您可以使用 stat

  1. 最后一次访问的时间
  2. 最后一次修改的时间
  3. 最后一次状态更改的时间

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

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

All you are able to get using stat is

  1. time of last access
  2. time of last modification
  3. time of last status change

Note: When using filesystem type ext4 crtime is available!

若沐 2024-10-02 17:09:07

这个小脚本可以获取 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. 如有必要,请将 /dev/sda4 替换为从 mount|grep ext4 获得的内容

This little script can get the creation date for 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

Example output:

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

  1. realpath is usually not installed by default. In Ubuntu eg. install it with sudo apt-get install realpath
  2. Replace /dev/sda4 if necessary with the one you get from mount|grep ext4
水波映月 2024-10-02 17:09:07

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

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

链接

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.

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

Links

羞稚 2024-10-02 17:09:07

根据 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”,因此这个想法肯定是无用的。

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.

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.

居里长安 2024-10-02 17:09:07

创建时间被称为文件出生时间,并且在某些文件系统上受支持,仅某些内核。命令将是 Mohsen Pahlavanzadeh 答案:

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

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

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

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:

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?.

地狱即天堂 2024-10-02 17:09:07

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

guys i just finished writing this script this script to find the creation date of a file using 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";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文