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

fen*_*nec 14 linux filesystems ubuntu

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

Tha*_*ama 23

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

您可以使用stat获得的所有内容

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

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


Att*_*lop 5

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

#!/bin/sh

fn=`realpath $1`
echo -n "Querying creation time of $1..."
sudo debugfs -R "stat $fn" /dev/sda4|grep crtime
Run Code Online (Sandbox Code Playgroud)

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

示例输出:

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

与 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: -
Run Code Online (Sandbox Code Playgroud)

笔记

  1. realpath默认情况下通常不安装。在 Ubuntu 例如。安装它sudo apt-get install realpath
  2. /dev/sda4如有必要,请替换为您从中获得的mount|grep ext4