Showing posts with label file creation time in linux. Show all posts
Showing posts with label file creation time in linux. Show all posts

Tuesday, April 24, 2012

How to know File creation time in Linux ?

In Linux or any Unix flavors, file-creation time isn't maintained. It will get change when the file-content changes. I tested and confirmed this 1.5 years before and shared my test results in this post.
http://ashok-linux-tips.blogspot.com/2010/11/finding-file-creation-time-in-linux.html

Now the good news is, with 'EXT4' file-system it is possible to get the File-creation time.

Here's the test results performed on a EXT4 file-system:
root@Linux-Mach # df -h
Filesystem            Size    Used   Avail   Use% Mounted on
/dev/sda2             3.8G  2.2G    1.4G   62%   /
/dev/sda3             4.6G  139M  4.3G    4%     /home
/dev/sda1              46M   11M   33M   25%   /boot
tmpfs                   333M     0      333M  0%    /dev/shm
root@Linux-Mach # cd /opt
root@Linux-Mach # touch sample_file
root@Linux-Mach # ls -l sample_file
-rw-r--r-- 1 root root 0 2012-04-24 18:35 sample_file                    # File-creation time is 18:35

root@Linux-Mach # date
Tue Apr 24 18:40:12 CDT 2012
root@Linux-Mach # cat > sample_file           
This is test file to check creation time of this file.
Ctrl+D
root@Linux-Mach # ls -l sample_file  
-rw-r--r-- 1 root root 29 2012-04-24 18:40 sample_file
root@Linux-Mach # ls -i sample_file  
135528 sample_file                                                                    # inode number  
root@Linux-Mach # debugfs -R 'stat <135528>' /dev/sda2          
Inode 14552801   Type regular    Mode  0644   Flags 0x80000
Generation 340511001    Version 0x0000000000000001
User  1000   Group  1000   Size 29 
File ACL 0    Directory ACL 0 
Links 1   Blockcount 8 
Fragment  Address 0    Number 0    Size 0
 ctime 0x3f1da5b513cbff4 -- Tue Apr 24 18:40:51 2012
 atime 0x3f1da5ec8725434 -- Tue Apr 24 18:40:54 2012
 mtime 0x3f1da5b513cbff4 -- Tue Apr 24 18:40:51 2012
crtime 0x3f1cacc966104fc -- Tue Apr 24 18:35:28 2012             # we could see file creation time    
Size of extra inode fields 28
EXTENTS
(0) 44665199
debugfs 1.41.11 (14-Mar-2010)
root@Linux-Mach #

Please note the entry "crtime"  which displays the file-creation time. In my view, this information would be of great help in certain situations.

Monday, November 15, 2010

Finding file creation time in Linux

Question:  In Linux, is it possible to find the actual time when a file was created first?

The Answer is NO until Ext3. 

File creation time ISN’T maintained in Linux with file-system Ext3 or earlier version. 
It will change when file content changes. It is explained with an example here:


[adevaraju@cac1-t1 ~]$ date
Tue Nov  9 01:22:25 CST 2010                                                      # Time now is 01:22:25
[adevaraju@cac01-t1 ~]$ echo "Some text on the file " > testfile       # Creating a file
[adevaraju@cac01-t1 ~]$ ls -lc testfile
-rw-r--r-- 1 adevaraju domain users 23 Nov  9 01:22 testfile     # Shows file change time as 01:22
 [adevaraju@cac01-t1 ~]$ ls -lu testfile
-rw-r--r-- 1 adevaraju domain users 23 Nov  9 01:22 testfile     # Access time is also 01:22

[adevaraju@cac01-t1 ~]$ cat testfile                                       # Now am accessing the file
Some text on the file

 [adevaraju@cac01-t1 ~]$ ls -lc testfile                            
-rw-r--r-- 1 adevaraju domain users 23 Nov  9 01:22 testfile     # Change time remains the same
[adevaraju@cac01-t1 ~]$ ls -lu testfile
-rw-r--r-- 1 adevaraju domain users 23 Nov  9 01:23 testfile     # Access time changed to 01:23
[adevaraju@cac01-t1 ~]$ date
Tue Nov  9 01:23:32 CST 2010

[adevaraju@cac01-t1 ~]$ echo "Additional text to the file" >> testfile # file content changed
 [adevaraju@cac01-t1 ~]$ ls -lc testfile                                                                            
-rw-r--r-- 1 adevaraju domain users 51 Nov  9 01:24 testfile      # Change time changes to 01:24
[adevaraju@cacllm01-t1 ~]$ ls -lu testfile
-rw-r--r-- 1 adevaraju domain users 51 Nov  9 01:23 testfile      # But access time remains the same since we did only changes to file.
[adevaraju@cacllm01-t1 ~]$ date
Tue Nov  9 01:24:22 CST 2010
[adevaraju@cacllm01-t1 ~]$

Atlast the original file creation time (which is 01:22) is gone, we CAN’T retrieve that information.

PS:  EXT4 file-system comes out with a feature to find the File-creation time.