Are there any (good known, reliable) file systems on Linux that store the creation time of files and directories in the i-node table?
If there are, is the "changed" time replaced by the creation time of an i-node in a stat call?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communityAre there any (good known, reliable) file systems on Linux that store the creation time of files and directories in the i-node table?
If there are, is the "changed" time replaced by the creation time of an i-node in a stat call?
Several file systems store the file creation time, although there is no standard name for this field:
xfs_db
manpage or in XFS File System Structure
Mar 28, 2015 at 13:54
crtime
: git.kernel.org/pub/scm/fs/xfs/xfs-documentation.git/tree/design/… — however, it appears that some kernels capable of XFS v5 mounting did not support crtime: unix.stackexchange.com/questions/306442/…
The ext4 file system does store the creation time. stat -c %W myfile
can show it to you.
stat -c %W
returns 0 (creation time unknown), but that is another question...
Feb 17, 2011 at 6:30
debugfs
and stat
which revealed that there is no crtime
. So I wonder if it needs to be enabled somehow? (FWIW I use Arch Linux)
stat -c %W
presumably works on (some) BSDs, but it can’t output non-0 on Linux.
Aug 28, 2018 at 15:57
As far as I know ext4, JFS and BTRFS file systems all support an extra field in the files inode to store the creation time, though the naming might differ.
Source: LWN File Creation Times
debugfs
command stat. Exemple: you need to thing the device where you ext4 filesystem is mounted (e.g. /dev/sda3) and you need to get a file inode number within that file system (use ls -i
, let say 42000 is the number), then you simply type: debugfs -R 'stat <42000>' /dev/sda3
. Run this as root, or with enough privilege. Look for the crtime
field, that's the one. For JFS and BTRFS, you would need to find the equivalent debugfs command...
df -T
to get the partition type or simply type mount
. Make sure that the file inode belong to the correct partition. Inodes are (per their nature) specific to a partition.
xfs v5 supports crtime
# dmesg | grep -iE 'xfs.*\s+mounting' | head -1
[ 10.939721] XFS (dm-1): Mounting V5 Filesystem
shows using V5. Then get file inode number ;
# stat -c '%i' test.txt
68227195
Then get crtime ;
# xfs_db -r -c "inode 68227195" -c "p v3.crtime.sec" <device eg. /dev/mapper/rl-root>
v3.crtime.sec = Mon Jun 6 15:13:02 2022
or on one line:
xfs_db -r -c "inode $(stat -c '%i' test.txt)" -c "p v3.crtime.sec" <device>
EDIT
...an easier way;
use stat <filename>
for the same result returned as "Birth
"
[root@wsa test]# pwd
/root/test
[root@wsa test]# ls
total 8.0K
67109562 0 drwxr-xr-x. 2 root root 22 Mar 22 00:07 .
133 4.0K dr-xr-x---. 19 root root 4.0K Mar 21 23:54 ..
67552174 4.0K -rw-r--r--. 1 root root 10 Mar 22 00:07 test.txt
[root@wsa test]# df .
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/al-root 104806400 25289868 79516532 25% /
[root@wsa test]# xfs_db -r -c "inode $(stat -c '%i' test.txt)" -c "p v3.crtime.sec" /dev/mapper/al-root
v3.crtime.sec = Tue Mar 21 23:55:55 2023
[root@wsa test]# stat test.txt
File: test.txt
Size: 10 Blocks: 8 IO Block: 4096 regular file
Device: fd01h/64769d Inode: 67552174 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Context: unconfined_u:object_r:admin_home_t:s0
Access: 2023-03-22 00:07:38.926108379 +0000
Modify: 2023-03-22 00:07:55.794041676 +0000
Change: 2023-03-22 00:07:55.794041676 +0000
Birth: 2023-03-21 23:55:55.413859045 +0000
performed with;
Operating System: AlmaLinux 8.7 (RHEL clone)
Kernel Version: 4.18.0-425.13.1.el8_7.x86_64 (64-bit)
[root@wsa test]# stat --version
stat (GNU coreutils) 8.30
Copyright (C) 2018 Free Software Foundation, Inc.
[root@wsa test]# xfs_db -r /dev/mapper/al-root
xfs_db> version
versionnum [0xb4b5+0x18a] = V5,NLINK,DIRV2,ATTR,ALIGN,LOGV2,EXTFLG,MOREBITS,ATTR2,LAZYSBCOUNT,PROJID32BIT,CRC,FTYPE,FINOBT,SPARSE_INODES,REFLINK
stat 8.22
does not read crtime on RH7: stat gives Birth : -
but xfs_db gives v3.crtime.sec = Tue Apr 11 12:58:52 2023