网站搜索

DEBUGFS 命令 - 显示 Linux 中的文件创建时间


在 Linux 等类 Unix 系统中,所有内容都被视为文件,并且有关文件的所有信息(元数据或文件属性,例如创建时间、最后修改时间等),除了实际文件内容之外,都存储在 inode 中,Linux通过索引节点号(而不是人类可读的文件名)来标识每个文件。

此外,Linux stat 程序是显示文件或文件系统状态的有用实用程序。它显示诸如索引节点号、文件生成时间、上次数据修改、上次访问、上次状态更改等信息。我们将结合这两个程序来查找 Linux 中的实际文件创建时间。

在本文中,我们将解释如何使用 debugfsstat 程序查找文件的关键属性之一,以获取文件的以下创建/访问信息Linux 文件系统。

  • ctime:显示文件更改时间。
  • atime:显示文件访问时间。
  • mtime:显示文件修改时间。
  • crtime:显示文件创建时间。

在 Linux 中查找文件创建日期

1.查找文件创建日期和时间“crtime”是针对名为“About-TecMint”的文件使用stat命令查找文件的inode ”

stat About-TecMint 

  File: 'About-TecMint'
  Size: 260       	Blocks: 8          IO Block: 4096   regular file
Device: 80ah/2058d	Inode: 14420015    Links: 1
Access: (0777/-rwxrwxrwx)  Uid: ( 1000/ tecmint)   Gid: ( 1000/ tecmint)
Access: 2017-02-23 14:15:20.263337740 +0530
Modify: 2015-10-22 15:08:25.236299000 +0530
Change: 2016-08-01 10:26:36.603280013 +0530
 Birth: -

或者,您可以对名为“About-TecMint”的文件使用 ls -i 命令。

ls -i About-TecMint
 
14420015 About-TecMint

从上述命令的输出来看,文件inode编号为14420015。请记下这个唯一的索引节点号,因为我们将在以下步骤中使用该索引节点号。

2. 现在我们需要找到文件所在的根文件系统,只需发出以下 df -h 命令来识别根文件系统。

df -h

Filesystem      Size  Used Avail Use% Mounted on
udev            3.9G     0  3.9G   0% /dev
tmpfs           788M  9.7M  779M   2% /run
/dev/sda10      324G  277G   31G  91% /
tmpfs           3.9G  192M  3.7G   5% /dev/shm
tmpfs           5.0M  4.0K  5.0M   1% /run/lock
tmpfs           3.9G     0  3.9G   0% /sys/fs/cgroup
/dev/loop3       87M   87M     0 100% /snap/core/4486
/dev/loop0       87M   87M     0 100% /snap/core/4407
/dev/loop1       82M   82M     0 100% /snap/core/4206
/dev/loop2      181M  181M     0 100% /snap/vlc/190
/dev/loop4      189M  189M     0 100% /snap/vlc/158
cgmfs           100K     0  100K   0% /run/cgmanager/fs
tmpfs           788M   40K  788M   1% /run/user/1000

从上面的输出中,根分区的文件系统是 /dev/sda10 (记下该文件系统)。这在您的系统上会有所不同。

3. 接下来,使用debugfs命令查找名为“About-TecMint”的文件的创建时间,其中- R 标志指示 debugfs 执行用 inode 号 14420015(本例中为 stat)指定的单个外部命令,然后退出。

sudo debugfs -R 'stat <14420015>' /dev/sda10

Inode: 14420015   Type: regular    Mode:  0777   Flags: 0x80000
Generation: 2130000141    Version: 0x00000000:00000001
User:  1000   Group:  1000   Size: 260
File ACL: 0    Directory ACL: 0
Links: 1   Blockcount: 8
Fragment:  Address: 0    Number: 0    Size: 0
 ctime: 0x579ed684:8fd54a34 -- Mon Aug  1 10:26:36 2016
 atime: 0x58aea120:3ec8dc30 -- Thu Feb 23 14:15:20 2017
 mtime: 0x5628ae91:38568be0 -- Thu Oct 22 15:08:25 2015
crtime: 0x579ed684:8fd54a34 -- Mon Aug  1 10:26:36 2016
Size of extra inode fields: 32
EXTENTS:
(0):57750808
(END)

从上面的输出可以清楚地看出,文件“About-TecMint”是由crtimeMon Aug 1 10:26:36 2016创建的>。您还将看到文件的“ctime”、“atime”和“mtime”。