views:

69

answers:

5

i am using ubuntu and want to know the creation time of a file even when it gets modified or accessed ?

+2  A: 

The closest attribute available is the "change time", also known as ctime. This is updated for various system calls, any that modify the inode, rather than the data it contains.

matt@stanley:~$ stat -c %z .bashrc 
2010-08-17 11:53:56.865431072 +1000

Links

Matt Joiner
A: 

Yup - stat(): http://manpages.ubuntu.com/manpages/hardy/man2/stat.2.html

Jeff Meyers
No - stat(): http://manpages.ubuntu.com/manpages/hardy/man2/stat.2.htm
dmeister
+6  A: 

Unfortunately Unix does not store the creation time of a file.

All you are able to get using stat is

  1. time of last access
  2. time of last modification
  3. time of last status change

Note: When using filesystem type ext4 crtime is available!

Further information:

Thariama
Links regarding ext4 crtime please.
Matt Joiner
http://snippets.dzone.com/posts/show/12121 or http://www.qa.com/about-qa/blogs/2010/july/creation-time-in-unix-yes---in-ext4
Thariama
+1  A: 

According to http://en.wikipedia.org/wiki/Comparison_of_file_systems, this is available for ext4, btfrs, FAT, NTFS, and UDF filesystems, plus some others you're unlikely to encounter. It's not available on ext2 or ext3, probably the most common file system formats in Ubuntu.

You'll need a kernel patch, though: http://lwn.net/Articles/394391/. Apparently this is because Linus rejected creation time attribute on the grounds that somebody called it an "otime" and somebody else called it a "btime", and therefore the idea must be useless.

MSalters
A: 

guys i just finished writing this script this script to find the creation date of a file using perl:

use File::stat;
if (  scalar( @ARGV ) == 0 ) {
 die("type  a file  name  ex:perl filestat.pl <filename>");    
}
my $filename =  $ARGV[0] ;
my @info = stat($filename);
print "Creation time :",scalar localtime stat($filename)->ctime;
print "\n";
fenec