I want to find out the creation date of particular file, not modification date or access date.
I have tried with ls -ltrh
and stat filename
.
fileslinuxstattimestamps
I want to find out the creation date of particular file, not modification date or access date.
I have tried with ls -ltrh
and stat filename
.
Best Answer
stat -c '%w' file
on filesystems that store creation time.Note that on Linux this requires
coreutils
8.31,glibc
2.28 and kernel version 4.11 or newer.The POSIX standard only defines three distinct timestamps to be stored for each file: the time of last data access, the time of last data modification, and the time the file status last changed.
Modern Linux filesystems, such as ext4, Btrfs, XFS (v5 and later) and JFS, do store the file creation time (aka birth time), but use different names for the field in question (
crtime
in ext4/XFS,otime
in Btrfs and JFS). Linux provides the statx(2) system call interface for retrieving the file birth time for filesystems that support it since kernel version 4.11. (So even when creation time support has been added to a filesystem, some deployed kernels have not immediately supported it, even after adding nominal support for that filesystem version, e.g., XFS v5.)As Craig Sanders and Mohsen Pahlevanzadeh pointed out,
stat
does support the%w
and%W
format specifiers for displaying the file birth time (in human readable format and in seconds since Epoch respectively) prior tocoreutils
version 8.31. However,coreutils
stat
uses thestatx()
system call where available to retrieve the birth time only since version 8.31. Prior tocoreutils
version 8.31stat
accessed the birth time via theget_stat_birthtime()
provided by gnulib (inlib/stat-time.h
), which gets the birth time from thest_birthtime
andst_birthtimensec
fields of thestat
structure returned by thestat()
system call. While for instance BSD systems (and in extension OS X) providest_birthtime
viastat
, Linux does not. This is whystat -c '%w' file
outputs-
(indicating an unknown creation time) on Linux prior tocoreutils
8.31 even for filesystems which do store the creation time internally.As Stephane Chazelas points out, some filesystems, such as ntfs-3g, expose the file creation times via extended file attributes.