When I type the following:
$ IFS=$'\n'; arr=( $(stat "/bin/bash") ); for i in ${arr[@]} ; do echo $i ; done
File: '/bin/bash'
Size: 1037528 Blocks: 2032 IO Block: 4096 regular file
Device: 823h/2083d Inode: 656086 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2017-05-23 16:38:03.848124217 -0600
Modify: 2017-05-16 06:49:55.000000000 -0600
Change: 2017-05-18 07:43:22.946694155 -0600
Birth: -
I see the Birth Date for /bin/bash
is null / empty. When is this field ever used and what purpose might it have in Linux when it works?
I appreciate there is a shorter way of using stat
but this came up during development cycle and I copy and pasted.
Birth time is the time when the file was created on the filesystem, also known as the file creation time (
crtime
on EXTFS). Note that, this is not defined by POSIX; only last access time (atime
), last modification time (mtime
) and the inode change time (ctime
) are mandated by POSIX.IIRC, Linux yet does not provide any interface for getting the birth time, there is a proposal for
xstat()
andfxstat()
, yet to be implemented.As @muru noted, the newer approach is
statx()
, which is merged in the mainline kernel recently. So, any (modified) userspace tool can leverage that (thestatx
structure now, see below) on any such recent kernel.Here
stx_btime
is the file creation time.In the meantime,
stat
is showing absence of the fields (or the empty values)st_birthtime
/st_birthtimesec
returned by thestat()
call, in thestat
structure:There are some tricks with filesystem level debugging request to get the creation info from FS metadata e.g. for EXTFS:
assuming the FS of the file in question is on partition
/dev/sda1
. You can extract the value ofcrtime
to get the creation time of the file.It should be the file creation time, but there is an outstanding issue, the gnu coreutils team waiting for
xstat()
support in the kernel.TODO: stat(1) and ls(1) support for birth time