Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get file creation date/time in Bash/Debian?

I'm using Bash on Debian GNU/Linux 6.0. Is it possible to get the file creation date/time? Not the modification date/time. ls -lh a.txt and stat -c %y a.txt both only give the modification time.

like image 917
NoodleFolk Avatar asked Feb 12 '13 21:02

NoodleFolk


People also ask

How can I tell when a file was created in bash?

The easiest way to get the file creation date is with the stat command. As we can see, the creation date is shown in the “Birth” field.

How do I find the creation time of a file?

The command is sudo debugfs -R 'stat /path/to/file' /dev/sdaX (replace sdaX with the device name of the filesystem on which the file resides). The creation time is the value of crtime . You can add | grep . [^ca]time to list just mtime (the modification time) and crtime (the creation time).

How do you get the date and time a file was created in Linux?

Find File Creation Date in Linux To find a file creation date and time “crtime” is to find the inode of the file using the stat command against a file called “About-TecMint”. Alternatively, you can use the ls -i command against a file called “About-TecMint”.

How do I see file time in Linux?

You can use the stat command to see all the timestamps of a file. Using stat command is very simple. You just need to provide the filename with it. You can see all three timestamps (access, modify and change) time in the above output.


1 Answers

Unfortunately your quest won't be possible in general, as there are only 3 distinct time values stored for each of your files as defined by the POSIX standard (see Base Definitions section 4.8 File Times Update)

Each file has three distinct associated timestamps: the time of last data access, the time of last data modification, and the time the file status last changed. These values are returned in the file characteristics structure struct stat, as described in <sys/stat.h>.

EDIT: As mentioned in the comments below, depending on the filesystem used metadata may contain file creation date. Note however storage of information like that is non standard. Depending on it may lead to portability problems moving to another filesystem, in case the one actually used somehow stores it anyways.

like image 84
mikyra Avatar answered Sep 28 '22 04:09

mikyra