How to find creation date of file?
up vote
97
down vote
favorite
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.
linux files timestamps stat
add a comment |
up vote
97
down vote
favorite
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.
linux files timestamps stat
5
Linux doesn't keep track of the creation time since it is not required by POSIX. However, Mac OS X does with the HFS filesystem — look under "birth time" instat(1).
– 200_success
Sep 18 '13 at 5:15
1
Fedora 19 ext4 filesystems do set file creation times. I'm sure there are many more examples. See answer below that usesstapto retrieve creation times.
– rickhg12hs
Oct 15 '13 at 13:11
1
see unix.stackexchange.com/questions/7562/…
– jlliagre
Feb 25 '14 at 19:08
add a comment |
up vote
97
down vote
favorite
up vote
97
down vote
favorite
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.
linux files timestamps stat
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.
linux files timestamps stat
linux files timestamps stat
edited Sep 18 '13 at 12:39
Thomas Nyman
20k74969
20k74969
asked Sep 18 '13 at 4:44
Özzesh
1,16361625
1,16361625
5
Linux doesn't keep track of the creation time since it is not required by POSIX. However, Mac OS X does with the HFS filesystem — look under "birth time" instat(1).
– 200_success
Sep 18 '13 at 5:15
1
Fedora 19 ext4 filesystems do set file creation times. I'm sure there are many more examples. See answer below that usesstapto retrieve creation times.
– rickhg12hs
Oct 15 '13 at 13:11
1
see unix.stackexchange.com/questions/7562/…
– jlliagre
Feb 25 '14 at 19:08
add a comment |
5
Linux doesn't keep track of the creation time since it is not required by POSIX. However, Mac OS X does with the HFS filesystem — look under "birth time" instat(1).
– 200_success
Sep 18 '13 at 5:15
1
Fedora 19 ext4 filesystems do set file creation times. I'm sure there are many more examples. See answer below that usesstapto retrieve creation times.
– rickhg12hs
Oct 15 '13 at 13:11
1
see unix.stackexchange.com/questions/7562/…
– jlliagre
Feb 25 '14 at 19:08
5
5
Linux doesn't keep track of the creation time since it is not required by POSIX. However, Mac OS X does with the HFS filesystem — look under "birth time" in
stat(1).– 200_success
Sep 18 '13 at 5:15
Linux doesn't keep track of the creation time since it is not required by POSIX. However, Mac OS X does with the HFS filesystem — look under "birth time" in
stat(1).– 200_success
Sep 18 '13 at 5:15
1
1
Fedora 19 ext4 filesystems do set file creation times. I'm sure there are many more examples. See answer below that uses
stap to retrieve creation times.– rickhg12hs
Oct 15 '13 at 13:11
Fedora 19 ext4 filesystems do set file creation times. I'm sure there are many more examples. See answer below that uses
stap to retrieve creation times.– rickhg12hs
Oct 15 '13 at 13:11
1
1
see unix.stackexchange.com/questions/7562/…
– jlliagre
Feb 25 '14 at 19:08
see unix.stackexchange.com/questions/7562/…
– jlliagre
Feb 25 '14 at 19:08
add a comment |
7 Answers
7
active
oldest
votes
up vote
82
down vote
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.
That said, modern Linux filesystems, such as ext4, Btrfs and JFS, do store the file creation time (aka birth time), but use different names for the field in question (crtime in ext4, otime in Btrfs and JFS). However, currently Linux does not provide a kernel API for accessing the file creation times, even on filesystems supporting them.
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). However, stat itself accesses the birth time via the get_stat_birthtime() provided by gnulib (in lib/stat-time.h), which gets the birth time from the st_birthtime and st_birthtimensec fields of the stat structure returned by the stat() system call. While for instance BSD systems (and in extension OS X) provide st_birthtime via stat, Linux does not. This is why stat -c '%w' file outputs - (indicating an unknown creation time) on Linux 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.
4
On Linux, it is now stored in many filesystems including ext4. There's no kernel API yet to get it though. Some file systems like ntfs-3g over fuse make it available via the extended attribute API
– Stéphane Chazelas
Sep 18 '13 at 6:30
@StephaneChazelas Thank you for your comments. Updated the answer to provide more details.
– Thomas Nyman
Sep 18 '13 at 8:06
You can usestapto create your own kernel API. See example in answer here.
– rickhg12hs
Oct 15 '13 at 13:12
add a comment |
up vote
24
down vote
TLDR; Use stap ("SystemTap") to create your own kernel API. Demo of ext4 creation time extraction below.
You can extract the ext4 creation times on Fedora 19 systems. Here's mine:
$ uname -a
Linux steelers.net 3.11.1-200.fc19.i686.PAE #1 SMP Sat Sep 14 15:20:42 UTC 2013 i686 i686 i386 GNU/Linux
It's clear that the inodes on my ext4 partitions have the creation time. Here's a shell script that determines the inode associated with a filename and then augments the stat output with the creation time by using stap ("systemtap").
NB: This is just a demo and hugely inefficient since a kernel module is created, loaded, and unloaded for every execution. This is also probably very fragile as no error checking is performed. A proper kernel API would be preferable, but this script could be made much more efficient and read the creation times of multiple files/inodes.
[contents of stap_stat.sh]
#/bin/sh
my_inode_str=$(stat --printf="%i" $1)
stap - << end_of_stap_script
global my_offsetof
probe begin {
system("stat $1");
my_offsetof = &@cast(0,"struct ext4_inode_info")->vfs_inode;
}
probe kernel.function("ext4_getattr@fs/ext4/inode.c") {
probe_inode=$dentry->d_inode;
if (@cast(probe_inode, "struct inode")->i_ino == $my_inode_str) {
my_i_crtime = &@cast(probe_inode - my_offsetof,"struct ext4_inode_info")->i_crtime;
printf("CrTime: %s GMTn", ctime(@cast(my_i_crtime, "timespec")->tv_sec));
printf("CrTime (nsecs): %dn", @cast(my_i_crtime, "timespec")->tv_nsec);
exit();
}
}
end_of_stap_script
Here's a demo:
$ ll testfile
ls: cannot access testfile: No such file or directory
$ touch testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:17:04.221441084 -0400
Change: 2013-09-28 06:17:04.221441084 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ ll testfile
-rw-rw-r--. 1 Rick Rick 0 Sep 28 06:17 testfile
$ cat - >> testfile
Now is the time ...
$ ll testfile
-rw-rw-r--. 1 Rick Rick 20 Sep 28 06:18 testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ cat testfile
Now is the time ...
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ mv testfile testfile2
$ ./stap_stat.sh testfile2
File: ‘testfile2’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:20:45.870295668 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$
4
Ok, that is just cool. +1 for using stap, monkey patching the linux kernel, awesome.
– Chris Magnuson
Jun 24 '15 at 1:20
@ChrisMagnuson:debugfs + statallow to getcrtimewithout monkey patching the kernel.
– jfs
Jul 26 '16 at 13:41
add a comment |
up vote
17
down vote
In ext4 it is possible; because ext4 file-system stores the file creation time. But still, you will find that the stat command is unable to show the date, because I think the kernel is not having any APIs for this.
Anyway, the file birth time is stored in ext4 and you can find it out, although not by a direct method, but by using debugfs
sudo debugfs -R "stat /ABSOLUTE/PATH" /dev/sdxX | grep crtime
1
as a bash function:xstat filename
– jfs
Jul 26 '16 at 13:39
1
If/dev/sdxXis mounted in/some/pathand the file is/some/path/some/file, the path to be specified is onlysome/file: its path must be referred not to the filesystem root, but to the mountpoint. Otherwise, the file won't be found.
– BowPark
Jun 27 at 13:33
add a comment |
up vote
15
down vote
In theory, with GNU stat you could use stat -c '%w' or %W to get a file's creation date (aka birthtime).
In practice, most filesystems do not record that information and the linux kernel does not provide any way of accessing it.
The closest you can get is the file's ctime, which is not the creation time, it is the time that the file's metadata was last changed.
Linux Weekly News had an interesting article about this a few years back - http://lwn.net/Articles/397442/
add a comment |
up vote
7
down vote
stat --printf='%w' yourfile #human readable
stat --printf='%W' yourfile #seconds from Epoch , 0 if unknown
Difference between FreeBSD and GNULinux on stat command:
If you call stat command in GNULinux it invokes the -x option, but in FreeBSD, you yourself should invoke the -x option.
See also What file systems on Linux store the creation time?
Notes: --printf is very useful in scripting....!
// , Tried this on a CEntOS 6 machine, and all I got were question marks: $ stat --printf='%w' ~/dump.rdb ? Maybe my file system doesn't support stat with %w.
– Nathan Basanese
Aug 21 '15 at 19:23
unfortunately, HFS doesn't support ctime.
– PersianGulf
Aug 22 '15 at 9:33
add a comment |
up vote
5
down vote
In OS X you can use ls -lU, stat -f%B, GetFileInfo -d, or mdls -n kMDItemFSCreationDate:
$ ls -lU
total 0
-rw-r--r-- 1 lauri staff 0 Apr 25 03:58 a
$ stat -f%B a
1398387538
$ stat -f%SB -t %Y%m%d%H%M a
201404250358
$ GetFileInfo -d a
04/25/2014 03:58:58
$ mdls -n kMDItemFSCreationDate a
kMDItemFSCreationDate = 2014-04-25 00:58:58 +0000
add a comment |
up vote
2
down vote
Check this out:
# the last arg is the device to scan in.
debugfs -R 'stat /home/renich/somefile' /dev/sda1
BTW, this works on ext4 only. I haven't found a solution for BtrFS... yet ;)
1
That's pretty much what beginer's answer says... isn't it ?
– don_crissti
Dec 28 '15 at 23:49
whoops, you're right @don_crissti
– Renich
Dec 30 '15 at 0:49
add a comment |
protected by Anthon Apr 6 '16 at 15:36
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
7 Answers
7
active
oldest
votes
7 Answers
7
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
82
down vote
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.
That said, modern Linux filesystems, such as ext4, Btrfs and JFS, do store the file creation time (aka birth time), but use different names for the field in question (crtime in ext4, otime in Btrfs and JFS). However, currently Linux does not provide a kernel API for accessing the file creation times, even on filesystems supporting them.
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). However, stat itself accesses the birth time via the get_stat_birthtime() provided by gnulib (in lib/stat-time.h), which gets the birth time from the st_birthtime and st_birthtimensec fields of the stat structure returned by the stat() system call. While for instance BSD systems (and in extension OS X) provide st_birthtime via stat, Linux does not. This is why stat -c '%w' file outputs - (indicating an unknown creation time) on Linux 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.
4
On Linux, it is now stored in many filesystems including ext4. There's no kernel API yet to get it though. Some file systems like ntfs-3g over fuse make it available via the extended attribute API
– Stéphane Chazelas
Sep 18 '13 at 6:30
@StephaneChazelas Thank you for your comments. Updated the answer to provide more details.
– Thomas Nyman
Sep 18 '13 at 8:06
You can usestapto create your own kernel API. See example in answer here.
– rickhg12hs
Oct 15 '13 at 13:12
add a comment |
up vote
82
down vote
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.
That said, modern Linux filesystems, such as ext4, Btrfs and JFS, do store the file creation time (aka birth time), but use different names for the field in question (crtime in ext4, otime in Btrfs and JFS). However, currently Linux does not provide a kernel API for accessing the file creation times, even on filesystems supporting them.
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). However, stat itself accesses the birth time via the get_stat_birthtime() provided by gnulib (in lib/stat-time.h), which gets the birth time from the st_birthtime and st_birthtimensec fields of the stat structure returned by the stat() system call. While for instance BSD systems (and in extension OS X) provide st_birthtime via stat, Linux does not. This is why stat -c '%w' file outputs - (indicating an unknown creation time) on Linux 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.
4
On Linux, it is now stored in many filesystems including ext4. There's no kernel API yet to get it though. Some file systems like ntfs-3g over fuse make it available via the extended attribute API
– Stéphane Chazelas
Sep 18 '13 at 6:30
@StephaneChazelas Thank you for your comments. Updated the answer to provide more details.
– Thomas Nyman
Sep 18 '13 at 8:06
You can usestapto create your own kernel API. See example in answer here.
– rickhg12hs
Oct 15 '13 at 13:12
add a comment |
up vote
82
down vote
up vote
82
down vote
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.
That said, modern Linux filesystems, such as ext4, Btrfs and JFS, do store the file creation time (aka birth time), but use different names for the field in question (crtime in ext4, otime in Btrfs and JFS). However, currently Linux does not provide a kernel API for accessing the file creation times, even on filesystems supporting them.
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). However, stat itself accesses the birth time via the get_stat_birthtime() provided by gnulib (in lib/stat-time.h), which gets the birth time from the st_birthtime and st_birthtimensec fields of the stat structure returned by the stat() system call. While for instance BSD systems (and in extension OS X) provide st_birthtime via stat, Linux does not. This is why stat -c '%w' file outputs - (indicating an unknown creation time) on Linux 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.
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.
That said, modern Linux filesystems, such as ext4, Btrfs and JFS, do store the file creation time (aka birth time), but use different names for the field in question (crtime in ext4, otime in Btrfs and JFS). However, currently Linux does not provide a kernel API for accessing the file creation times, even on filesystems supporting them.
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). However, stat itself accesses the birth time via the get_stat_birthtime() provided by gnulib (in lib/stat-time.h), which gets the birth time from the st_birthtime and st_birthtimensec fields of the stat structure returned by the stat() system call. While for instance BSD systems (and in extension OS X) provide st_birthtime via stat, Linux does not. This is why stat -c '%w' file outputs - (indicating an unknown creation time) on Linux 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.
edited Apr 13 '17 at 12:36
Community♦
1
1
answered Sep 18 '13 at 5:00
Thomas Nyman
20k74969
20k74969
4
On Linux, it is now stored in many filesystems including ext4. There's no kernel API yet to get it though. Some file systems like ntfs-3g over fuse make it available via the extended attribute API
– Stéphane Chazelas
Sep 18 '13 at 6:30
@StephaneChazelas Thank you for your comments. Updated the answer to provide more details.
– Thomas Nyman
Sep 18 '13 at 8:06
You can usestapto create your own kernel API. See example in answer here.
– rickhg12hs
Oct 15 '13 at 13:12
add a comment |
4
On Linux, it is now stored in many filesystems including ext4. There's no kernel API yet to get it though. Some file systems like ntfs-3g over fuse make it available via the extended attribute API
– Stéphane Chazelas
Sep 18 '13 at 6:30
@StephaneChazelas Thank you for your comments. Updated the answer to provide more details.
– Thomas Nyman
Sep 18 '13 at 8:06
You can usestapto create your own kernel API. See example in answer here.
– rickhg12hs
Oct 15 '13 at 13:12
4
4
On Linux, it is now stored in many filesystems including ext4. There's no kernel API yet to get it though. Some file systems like ntfs-3g over fuse make it available via the extended attribute API
– Stéphane Chazelas
Sep 18 '13 at 6:30
On Linux, it is now stored in many filesystems including ext4. There's no kernel API yet to get it though. Some file systems like ntfs-3g over fuse make it available via the extended attribute API
– Stéphane Chazelas
Sep 18 '13 at 6:30
@StephaneChazelas Thank you for your comments. Updated the answer to provide more details.
– Thomas Nyman
Sep 18 '13 at 8:06
@StephaneChazelas Thank you for your comments. Updated the answer to provide more details.
– Thomas Nyman
Sep 18 '13 at 8:06
You can use
stap to create your own kernel API. See example in answer here.– rickhg12hs
Oct 15 '13 at 13:12
You can use
stap to create your own kernel API. See example in answer here.– rickhg12hs
Oct 15 '13 at 13:12
add a comment |
up vote
24
down vote
TLDR; Use stap ("SystemTap") to create your own kernel API. Demo of ext4 creation time extraction below.
You can extract the ext4 creation times on Fedora 19 systems. Here's mine:
$ uname -a
Linux steelers.net 3.11.1-200.fc19.i686.PAE #1 SMP Sat Sep 14 15:20:42 UTC 2013 i686 i686 i386 GNU/Linux
It's clear that the inodes on my ext4 partitions have the creation time. Here's a shell script that determines the inode associated with a filename and then augments the stat output with the creation time by using stap ("systemtap").
NB: This is just a demo and hugely inefficient since a kernel module is created, loaded, and unloaded for every execution. This is also probably very fragile as no error checking is performed. A proper kernel API would be preferable, but this script could be made much more efficient and read the creation times of multiple files/inodes.
[contents of stap_stat.sh]
#/bin/sh
my_inode_str=$(stat --printf="%i" $1)
stap - << end_of_stap_script
global my_offsetof
probe begin {
system("stat $1");
my_offsetof = &@cast(0,"struct ext4_inode_info")->vfs_inode;
}
probe kernel.function("ext4_getattr@fs/ext4/inode.c") {
probe_inode=$dentry->d_inode;
if (@cast(probe_inode, "struct inode")->i_ino == $my_inode_str) {
my_i_crtime = &@cast(probe_inode - my_offsetof,"struct ext4_inode_info")->i_crtime;
printf("CrTime: %s GMTn", ctime(@cast(my_i_crtime, "timespec")->tv_sec));
printf("CrTime (nsecs): %dn", @cast(my_i_crtime, "timespec")->tv_nsec);
exit();
}
}
end_of_stap_script
Here's a demo:
$ ll testfile
ls: cannot access testfile: No such file or directory
$ touch testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:17:04.221441084 -0400
Change: 2013-09-28 06:17:04.221441084 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ ll testfile
-rw-rw-r--. 1 Rick Rick 0 Sep 28 06:17 testfile
$ cat - >> testfile
Now is the time ...
$ ll testfile
-rw-rw-r--. 1 Rick Rick 20 Sep 28 06:18 testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ cat testfile
Now is the time ...
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ mv testfile testfile2
$ ./stap_stat.sh testfile2
File: ‘testfile2’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:20:45.870295668 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$
4
Ok, that is just cool. +1 for using stap, monkey patching the linux kernel, awesome.
– Chris Magnuson
Jun 24 '15 at 1:20
@ChrisMagnuson:debugfs + statallow to getcrtimewithout monkey patching the kernel.
– jfs
Jul 26 '16 at 13:41
add a comment |
up vote
24
down vote
TLDR; Use stap ("SystemTap") to create your own kernel API. Demo of ext4 creation time extraction below.
You can extract the ext4 creation times on Fedora 19 systems. Here's mine:
$ uname -a
Linux steelers.net 3.11.1-200.fc19.i686.PAE #1 SMP Sat Sep 14 15:20:42 UTC 2013 i686 i686 i386 GNU/Linux
It's clear that the inodes on my ext4 partitions have the creation time. Here's a shell script that determines the inode associated with a filename and then augments the stat output with the creation time by using stap ("systemtap").
NB: This is just a demo and hugely inefficient since a kernel module is created, loaded, and unloaded for every execution. This is also probably very fragile as no error checking is performed. A proper kernel API would be preferable, but this script could be made much more efficient and read the creation times of multiple files/inodes.
[contents of stap_stat.sh]
#/bin/sh
my_inode_str=$(stat --printf="%i" $1)
stap - << end_of_stap_script
global my_offsetof
probe begin {
system("stat $1");
my_offsetof = &@cast(0,"struct ext4_inode_info")->vfs_inode;
}
probe kernel.function("ext4_getattr@fs/ext4/inode.c") {
probe_inode=$dentry->d_inode;
if (@cast(probe_inode, "struct inode")->i_ino == $my_inode_str) {
my_i_crtime = &@cast(probe_inode - my_offsetof,"struct ext4_inode_info")->i_crtime;
printf("CrTime: %s GMTn", ctime(@cast(my_i_crtime, "timespec")->tv_sec));
printf("CrTime (nsecs): %dn", @cast(my_i_crtime, "timespec")->tv_nsec);
exit();
}
}
end_of_stap_script
Here's a demo:
$ ll testfile
ls: cannot access testfile: No such file or directory
$ touch testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:17:04.221441084 -0400
Change: 2013-09-28 06:17:04.221441084 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ ll testfile
-rw-rw-r--. 1 Rick Rick 0 Sep 28 06:17 testfile
$ cat - >> testfile
Now is the time ...
$ ll testfile
-rw-rw-r--. 1 Rick Rick 20 Sep 28 06:18 testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ cat testfile
Now is the time ...
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ mv testfile testfile2
$ ./stap_stat.sh testfile2
File: ‘testfile2’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:20:45.870295668 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$
4
Ok, that is just cool. +1 for using stap, monkey patching the linux kernel, awesome.
– Chris Magnuson
Jun 24 '15 at 1:20
@ChrisMagnuson:debugfs + statallow to getcrtimewithout monkey patching the kernel.
– jfs
Jul 26 '16 at 13:41
add a comment |
up vote
24
down vote
up vote
24
down vote
TLDR; Use stap ("SystemTap") to create your own kernel API. Demo of ext4 creation time extraction below.
You can extract the ext4 creation times on Fedora 19 systems. Here's mine:
$ uname -a
Linux steelers.net 3.11.1-200.fc19.i686.PAE #1 SMP Sat Sep 14 15:20:42 UTC 2013 i686 i686 i386 GNU/Linux
It's clear that the inodes on my ext4 partitions have the creation time. Here's a shell script that determines the inode associated with a filename and then augments the stat output with the creation time by using stap ("systemtap").
NB: This is just a demo and hugely inefficient since a kernel module is created, loaded, and unloaded for every execution. This is also probably very fragile as no error checking is performed. A proper kernel API would be preferable, but this script could be made much more efficient and read the creation times of multiple files/inodes.
[contents of stap_stat.sh]
#/bin/sh
my_inode_str=$(stat --printf="%i" $1)
stap - << end_of_stap_script
global my_offsetof
probe begin {
system("stat $1");
my_offsetof = &@cast(0,"struct ext4_inode_info")->vfs_inode;
}
probe kernel.function("ext4_getattr@fs/ext4/inode.c") {
probe_inode=$dentry->d_inode;
if (@cast(probe_inode, "struct inode")->i_ino == $my_inode_str) {
my_i_crtime = &@cast(probe_inode - my_offsetof,"struct ext4_inode_info")->i_crtime;
printf("CrTime: %s GMTn", ctime(@cast(my_i_crtime, "timespec")->tv_sec));
printf("CrTime (nsecs): %dn", @cast(my_i_crtime, "timespec")->tv_nsec);
exit();
}
}
end_of_stap_script
Here's a demo:
$ ll testfile
ls: cannot access testfile: No such file or directory
$ touch testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:17:04.221441084 -0400
Change: 2013-09-28 06:17:04.221441084 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ ll testfile
-rw-rw-r--. 1 Rick Rick 0 Sep 28 06:17 testfile
$ cat - >> testfile
Now is the time ...
$ ll testfile
-rw-rw-r--. 1 Rick Rick 20 Sep 28 06:18 testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ cat testfile
Now is the time ...
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ mv testfile testfile2
$ ./stap_stat.sh testfile2
File: ‘testfile2’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:20:45.870295668 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$
TLDR; Use stap ("SystemTap") to create your own kernel API. Demo of ext4 creation time extraction below.
You can extract the ext4 creation times on Fedora 19 systems. Here's mine:
$ uname -a
Linux steelers.net 3.11.1-200.fc19.i686.PAE #1 SMP Sat Sep 14 15:20:42 UTC 2013 i686 i686 i386 GNU/Linux
It's clear that the inodes on my ext4 partitions have the creation time. Here's a shell script that determines the inode associated with a filename and then augments the stat output with the creation time by using stap ("systemtap").
NB: This is just a demo and hugely inefficient since a kernel module is created, loaded, and unloaded for every execution. This is also probably very fragile as no error checking is performed. A proper kernel API would be preferable, but this script could be made much more efficient and read the creation times of multiple files/inodes.
[contents of stap_stat.sh]
#/bin/sh
my_inode_str=$(stat --printf="%i" $1)
stap - << end_of_stap_script
global my_offsetof
probe begin {
system("stat $1");
my_offsetof = &@cast(0,"struct ext4_inode_info")->vfs_inode;
}
probe kernel.function("ext4_getattr@fs/ext4/inode.c") {
probe_inode=$dentry->d_inode;
if (@cast(probe_inode, "struct inode")->i_ino == $my_inode_str) {
my_i_crtime = &@cast(probe_inode - my_offsetof,"struct ext4_inode_info")->i_crtime;
printf("CrTime: %s GMTn", ctime(@cast(my_i_crtime, "timespec")->tv_sec));
printf("CrTime (nsecs): %dn", @cast(my_i_crtime, "timespec")->tv_nsec);
exit();
}
}
end_of_stap_script
Here's a demo:
$ ll testfile
ls: cannot access testfile: No such file or directory
$ touch testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:17:04.221441084 -0400
Change: 2013-09-28 06:17:04.221441084 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ ll testfile
-rw-rw-r--. 1 Rick Rick 0 Sep 28 06:17 testfile
$ cat - >> testfile
Now is the time ...
$ ll testfile
-rw-rw-r--. 1 Rick Rick 20 Sep 28 06:18 testfile
$ ./stap_stat.sh testfile
File: ‘testfile’
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:17:04.221441084 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ cat testfile
Now is the time ...
$ ./stap_stat.sh testfile
File: ‘testfile’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:18:33.684374740 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$ mv testfile testfile2
$ ./stap_stat.sh testfile2
File: ‘testfile2’
Size: 20 Blocks: 8 IO Block: 4096 regular file
Device: fd02h/64770d Inode: 4850501 Links: 1
Access: (0664/-rw-rw-r--) Uid: ( 1001/ Rick) Gid: ( 1001/ Rick)
Context: unconfined_u:object_r:user_home_t:s0
Access: 2013-09-28 06:19:12.199349463 -0400
Modify: 2013-09-28 06:18:33.684374740 -0400
Change: 2013-09-28 06:20:45.870295668 -0400
Birth: -
CrTime: Sat Sep 28 10:17:04 2013 GMT
CrTime (nsecs): 220441085
$
edited Sep 28 '13 at 14:44
answered Sep 28 '13 at 10:30
rickhg12hs
861413
861413
4
Ok, that is just cool. +1 for using stap, monkey patching the linux kernel, awesome.
– Chris Magnuson
Jun 24 '15 at 1:20
@ChrisMagnuson:debugfs + statallow to getcrtimewithout monkey patching the kernel.
– jfs
Jul 26 '16 at 13:41
add a comment |
4
Ok, that is just cool. +1 for using stap, monkey patching the linux kernel, awesome.
– Chris Magnuson
Jun 24 '15 at 1:20
@ChrisMagnuson:debugfs + statallow to getcrtimewithout monkey patching the kernel.
– jfs
Jul 26 '16 at 13:41
4
4
Ok, that is just cool. +1 for using stap, monkey patching the linux kernel, awesome.
– Chris Magnuson
Jun 24 '15 at 1:20
Ok, that is just cool. +1 for using stap, monkey patching the linux kernel, awesome.
– Chris Magnuson
Jun 24 '15 at 1:20
@ChrisMagnuson:
debugfs + stat allow to get crtime without monkey patching the kernel.– jfs
Jul 26 '16 at 13:41
@ChrisMagnuson:
debugfs + stat allow to get crtime without monkey patching the kernel.– jfs
Jul 26 '16 at 13:41
add a comment |
up vote
17
down vote
In ext4 it is possible; because ext4 file-system stores the file creation time. But still, you will find that the stat command is unable to show the date, because I think the kernel is not having any APIs for this.
Anyway, the file birth time is stored in ext4 and you can find it out, although not by a direct method, but by using debugfs
sudo debugfs -R "stat /ABSOLUTE/PATH" /dev/sdxX | grep crtime
1
as a bash function:xstat filename
– jfs
Jul 26 '16 at 13:39
1
If/dev/sdxXis mounted in/some/pathand the file is/some/path/some/file, the path to be specified is onlysome/file: its path must be referred not to the filesystem root, but to the mountpoint. Otherwise, the file won't be found.
– BowPark
Jun 27 at 13:33
add a comment |
up vote
17
down vote
In ext4 it is possible; because ext4 file-system stores the file creation time. But still, you will find that the stat command is unable to show the date, because I think the kernel is not having any APIs for this.
Anyway, the file birth time is stored in ext4 and you can find it out, although not by a direct method, but by using debugfs
sudo debugfs -R "stat /ABSOLUTE/PATH" /dev/sdxX | grep crtime
1
as a bash function:xstat filename
– jfs
Jul 26 '16 at 13:39
1
If/dev/sdxXis mounted in/some/pathand the file is/some/path/some/file, the path to be specified is onlysome/file: its path must be referred not to the filesystem root, but to the mountpoint. Otherwise, the file won't be found.
– BowPark
Jun 27 at 13:33
add a comment |
up vote
17
down vote
up vote
17
down vote
In ext4 it is possible; because ext4 file-system stores the file creation time. But still, you will find that the stat command is unable to show the date, because I think the kernel is not having any APIs for this.
Anyway, the file birth time is stored in ext4 and you can find it out, although not by a direct method, but by using debugfs
sudo debugfs -R "stat /ABSOLUTE/PATH" /dev/sdxX | grep crtime
In ext4 it is possible; because ext4 file-system stores the file creation time. But still, you will find that the stat command is unable to show the date, because I think the kernel is not having any APIs for this.
Anyway, the file birth time is stored in ext4 and you can find it out, although not by a direct method, but by using debugfs
sudo debugfs -R "stat /ABSOLUTE/PATH" /dev/sdxX | grep crtime
edited 2 days ago
Community♦
1
1
answered Sep 14 '14 at 13:43
beginer
1,9881116
1,9881116
1
as a bash function:xstat filename
– jfs
Jul 26 '16 at 13:39
1
If/dev/sdxXis mounted in/some/pathand the file is/some/path/some/file, the path to be specified is onlysome/file: its path must be referred not to the filesystem root, but to the mountpoint. Otherwise, the file won't be found.
– BowPark
Jun 27 at 13:33
add a comment |
1
as a bash function:xstat filename
– jfs
Jul 26 '16 at 13:39
1
If/dev/sdxXis mounted in/some/pathand the file is/some/path/some/file, the path to be specified is onlysome/file: its path must be referred not to the filesystem root, but to the mountpoint. Otherwise, the file won't be found.
– BowPark
Jun 27 at 13:33
1
1
as a bash function:
xstat filename– jfs
Jul 26 '16 at 13:39
as a bash function:
xstat filename– jfs
Jul 26 '16 at 13:39
1
1
If
/dev/sdxX is mounted in /some/path and the file is /some/path/some/file, the path to be specified is only some/file: its path must be referred not to the filesystem root, but to the mountpoint. Otherwise, the file won't be found.– BowPark
Jun 27 at 13:33
If
/dev/sdxX is mounted in /some/path and the file is /some/path/some/file, the path to be specified is only some/file: its path must be referred not to the filesystem root, but to the mountpoint. Otherwise, the file won't be found.– BowPark
Jun 27 at 13:33
add a comment |
up vote
15
down vote
In theory, with GNU stat you could use stat -c '%w' or %W to get a file's creation date (aka birthtime).
In practice, most filesystems do not record that information and the linux kernel does not provide any way of accessing it.
The closest you can get is the file's ctime, which is not the creation time, it is the time that the file's metadata was last changed.
Linux Weekly News had an interesting article about this a few years back - http://lwn.net/Articles/397442/
add a comment |
up vote
15
down vote
In theory, with GNU stat you could use stat -c '%w' or %W to get a file's creation date (aka birthtime).
In practice, most filesystems do not record that information and the linux kernel does not provide any way of accessing it.
The closest you can get is the file's ctime, which is not the creation time, it is the time that the file's metadata was last changed.
Linux Weekly News had an interesting article about this a few years back - http://lwn.net/Articles/397442/
add a comment |
up vote
15
down vote
up vote
15
down vote
In theory, with GNU stat you could use stat -c '%w' or %W to get a file's creation date (aka birthtime).
In practice, most filesystems do not record that information and the linux kernel does not provide any way of accessing it.
The closest you can get is the file's ctime, which is not the creation time, it is the time that the file's metadata was last changed.
Linux Weekly News had an interesting article about this a few years back - http://lwn.net/Articles/397442/
In theory, with GNU stat you could use stat -c '%w' or %W to get a file's creation date (aka birthtime).
In practice, most filesystems do not record that information and the linux kernel does not provide any way of accessing it.
The closest you can get is the file's ctime, which is not the creation time, it is the time that the file's metadata was last changed.
Linux Weekly News had an interesting article about this a few years back - http://lwn.net/Articles/397442/
answered Sep 18 '13 at 5:02
cas
38.5k450100
38.5k450100
add a comment |
add a comment |
up vote
7
down vote
stat --printf='%w' yourfile #human readable
stat --printf='%W' yourfile #seconds from Epoch , 0 if unknown
Difference between FreeBSD and GNULinux on stat command:
If you call stat command in GNULinux it invokes the -x option, but in FreeBSD, you yourself should invoke the -x option.
See also What file systems on Linux store the creation time?
Notes: --printf is very useful in scripting....!
// , Tried this on a CEntOS 6 machine, and all I got were question marks: $ stat --printf='%w' ~/dump.rdb ? Maybe my file system doesn't support stat with %w.
– Nathan Basanese
Aug 21 '15 at 19:23
unfortunately, HFS doesn't support ctime.
– PersianGulf
Aug 22 '15 at 9:33
add a comment |
up vote
7
down vote
stat --printf='%w' yourfile #human readable
stat --printf='%W' yourfile #seconds from Epoch , 0 if unknown
Difference between FreeBSD and GNULinux on stat command:
If you call stat command in GNULinux it invokes the -x option, but in FreeBSD, you yourself should invoke the -x option.
See also What file systems on Linux store the creation time?
Notes: --printf is very useful in scripting....!
// , Tried this on a CEntOS 6 machine, and all I got were question marks: $ stat --printf='%w' ~/dump.rdb ? Maybe my file system doesn't support stat with %w.
– Nathan Basanese
Aug 21 '15 at 19:23
unfortunately, HFS doesn't support ctime.
– PersianGulf
Aug 22 '15 at 9:33
add a comment |
up vote
7
down vote
up vote
7
down vote
stat --printf='%w' yourfile #human readable
stat --printf='%W' yourfile #seconds from Epoch , 0 if unknown
Difference between FreeBSD and GNULinux on stat command:
If you call stat command in GNULinux it invokes the -x option, but in FreeBSD, you yourself should invoke the -x option.
See also What file systems on Linux store the creation time?
Notes: --printf is very useful in scripting....!
stat --printf='%w' yourfile #human readable
stat --printf='%W' yourfile #seconds from Epoch , 0 if unknown
Difference between FreeBSD and GNULinux on stat command:
If you call stat command in GNULinux it invokes the -x option, but in FreeBSD, you yourself should invoke the -x option.
See also What file systems on Linux store the creation time?
Notes: --printf is very useful in scripting....!
edited Apr 13 '17 at 12:37
Community♦
1
1
answered Sep 18 '13 at 6:35
PersianGulf
6,85543459
6,85543459
// , Tried this on a CEntOS 6 machine, and all I got were question marks: $ stat --printf='%w' ~/dump.rdb ? Maybe my file system doesn't support stat with %w.
– Nathan Basanese
Aug 21 '15 at 19:23
unfortunately, HFS doesn't support ctime.
– PersianGulf
Aug 22 '15 at 9:33
add a comment |
// , Tried this on a CEntOS 6 machine, and all I got were question marks: $ stat --printf='%w' ~/dump.rdb ? Maybe my file system doesn't support stat with %w.
– Nathan Basanese
Aug 21 '15 at 19:23
unfortunately, HFS doesn't support ctime.
– PersianGulf
Aug 22 '15 at 9:33
// , Tried this on a CEntOS 6 machine, and all I got were question marks: $ stat --printf='%w' ~/dump.rdb ? Maybe my file system doesn't support stat with %w.
– Nathan Basanese
Aug 21 '15 at 19:23
// , Tried this on a CEntOS 6 machine, and all I got were question marks: $ stat --printf='%w' ~/dump.rdb ? Maybe my file system doesn't support stat with %w.
– Nathan Basanese
Aug 21 '15 at 19:23
unfortunately, HFS doesn't support ctime.
– PersianGulf
Aug 22 '15 at 9:33
unfortunately, HFS doesn't support ctime.
– PersianGulf
Aug 22 '15 at 9:33
add a comment |
up vote
5
down vote
In OS X you can use ls -lU, stat -f%B, GetFileInfo -d, or mdls -n kMDItemFSCreationDate:
$ ls -lU
total 0
-rw-r--r-- 1 lauri staff 0 Apr 25 03:58 a
$ stat -f%B a
1398387538
$ stat -f%SB -t %Y%m%d%H%M a
201404250358
$ GetFileInfo -d a
04/25/2014 03:58:58
$ mdls -n kMDItemFSCreationDate a
kMDItemFSCreationDate = 2014-04-25 00:58:58 +0000
add a comment |
up vote
5
down vote
In OS X you can use ls -lU, stat -f%B, GetFileInfo -d, or mdls -n kMDItemFSCreationDate:
$ ls -lU
total 0
-rw-r--r-- 1 lauri staff 0 Apr 25 03:58 a
$ stat -f%B a
1398387538
$ stat -f%SB -t %Y%m%d%H%M a
201404250358
$ GetFileInfo -d a
04/25/2014 03:58:58
$ mdls -n kMDItemFSCreationDate a
kMDItemFSCreationDate = 2014-04-25 00:58:58 +0000
add a comment |
up vote
5
down vote
up vote
5
down vote
In OS X you can use ls -lU, stat -f%B, GetFileInfo -d, or mdls -n kMDItemFSCreationDate:
$ ls -lU
total 0
-rw-r--r-- 1 lauri staff 0 Apr 25 03:58 a
$ stat -f%B a
1398387538
$ stat -f%SB -t %Y%m%d%H%M a
201404250358
$ GetFileInfo -d a
04/25/2014 03:58:58
$ mdls -n kMDItemFSCreationDate a
kMDItemFSCreationDate = 2014-04-25 00:58:58 +0000
In OS X you can use ls -lU, stat -f%B, GetFileInfo -d, or mdls -n kMDItemFSCreationDate:
$ ls -lU
total 0
-rw-r--r-- 1 lauri staff 0 Apr 25 03:58 a
$ stat -f%B a
1398387538
$ stat -f%SB -t %Y%m%d%H%M a
201404250358
$ GetFileInfo -d a
04/25/2014 03:58:58
$ mdls -n kMDItemFSCreationDate a
kMDItemFSCreationDate = 2014-04-25 00:58:58 +0000
answered Apr 25 '14 at 1:07
user495470
3,23511516
3,23511516
add a comment |
add a comment |
up vote
2
down vote
Check this out:
# the last arg is the device to scan in.
debugfs -R 'stat /home/renich/somefile' /dev/sda1
BTW, this works on ext4 only. I haven't found a solution for BtrFS... yet ;)
1
That's pretty much what beginer's answer says... isn't it ?
– don_crissti
Dec 28 '15 at 23:49
whoops, you're right @don_crissti
– Renich
Dec 30 '15 at 0:49
add a comment |
up vote
2
down vote
Check this out:
# the last arg is the device to scan in.
debugfs -R 'stat /home/renich/somefile' /dev/sda1
BTW, this works on ext4 only. I haven't found a solution for BtrFS... yet ;)
1
That's pretty much what beginer's answer says... isn't it ?
– don_crissti
Dec 28 '15 at 23:49
whoops, you're right @don_crissti
– Renich
Dec 30 '15 at 0:49
add a comment |
up vote
2
down vote
up vote
2
down vote
Check this out:
# the last arg is the device to scan in.
debugfs -R 'stat /home/renich/somefile' /dev/sda1
BTW, this works on ext4 only. I haven't found a solution for BtrFS... yet ;)
Check this out:
# the last arg is the device to scan in.
debugfs -R 'stat /home/renich/somefile' /dev/sda1
BTW, this works on ext4 only. I haven't found a solution for BtrFS... yet ;)
answered Dec 28 '15 at 23:40
Renich
292
292
1
That's pretty much what beginer's answer says... isn't it ?
– don_crissti
Dec 28 '15 at 23:49
whoops, you're right @don_crissti
– Renich
Dec 30 '15 at 0:49
add a comment |
1
That's pretty much what beginer's answer says... isn't it ?
– don_crissti
Dec 28 '15 at 23:49
whoops, you're right @don_crissti
– Renich
Dec 30 '15 at 0:49
1
1
That's pretty much what beginer's answer says... isn't it ?
– don_crissti
Dec 28 '15 at 23:49
That's pretty much what beginer's answer says... isn't it ?
– don_crissti
Dec 28 '15 at 23:49
whoops, you're right @don_crissti
– Renich
Dec 30 '15 at 0:49
whoops, you're right @don_crissti
– Renich
Dec 30 '15 at 0:49
add a comment |
protected by Anthon Apr 6 '16 at 15:36
Thank you for your interest in this question.
Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).
Would you like to answer one of these unanswered questions instead?
5
Linux doesn't keep track of the creation time since it is not required by POSIX. However, Mac OS X does with the HFS filesystem — look under "birth time" in
stat(1).– 200_success
Sep 18 '13 at 5:15
1
Fedora 19 ext4 filesystems do set file creation times. I'm sure there are many more examples. See answer below that uses
stapto retrieve creation times.– rickhg12hs
Oct 15 '13 at 13:11
1
see unix.stackexchange.com/questions/7562/…
– jlliagre
Feb 25 '14 at 19:08