Getting file creation time in Linux
I’ve known for awhile that getting the creation time of a file in Linux isn’t an easy task. There are three timestamps on every file: modified time, access time, and change time. Change time acts like modified time except it also changes if the file’s attributes change. Access time is the last time the file was opened. POSIX has no timestamp for when the file was created. However, most modern file systems do (ext4, btrfs, zfs and others).
Despite file system for support for creation time, actually getting the value isn’t trivial. The function stat can print the birth field, but it is often blank. This is because the POSIX C function stat doesn’t include creation time. In Linux there is a new function called statx (get file status extended) which includes the creation time. It requires a kernel of at least 4.11, and glibc 2.28.
However, just because those requirements are met doesn’t mean the stat command line utility will use statx. For that one needs GNU coreutil of at least version 8.31. Currently the version of coreutil on Mint is 8.30. So close.
I decided today I could no longer live without having creation time. To get this functionality one just needs to download and compile the latest coreutil and I found a website that described the process. The setup took much longer than the compile itself. Running parallel on 16 threads makes quick work out of many builds. I installed it and just like that I had the file creation time showing up in the stat command output.
File: temp Size: 5 Blocks: 8 IO Block: 4096 regular file Device: 3bh/59d Inode: 86528 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ que) Gid: ( 1000/ que) Access: 2021-10-21 10:36:08.885699682 -0500 Modify: 2021-10-21 10:35:53.401775358 -0500 Change: 2021-10-21 10:35:53.401775358 -0500 Birth: -
File: temp Size: 5 Blocks: 8 IO Block: 4096 regular file Device: 9,0 Inode: 30225103 Links: 1 Access: (0664/-rw-rw-r--) Uid: ( 1000/ que) Gid: ( 1000/ que) Access: 2021-10-21 10:36:08.885699682 -0500 Modify: 2021-10-21 10:35:53.401775358 -0500 Change: 2021-10-21 10:35:53.401775358 -0500 Birth: 2021-10-21 10:33:05.154597661 -0500