linux date – Distro-Agnostic Way to Determine OS Install Date

datelinux

I am on a CrunchBang machine and trying to write a script that needs to have the OS install date as a reference.

I searched and found this command:

ls -lct /etc | tail -1 | awk '{print $6, $7, $8}'

It prints

Mar 31 21:24

I did not understand the tail -1 part, but was able figure out that $6 $7 $8 are the 6th 7th 8th occurrences of the last line that the command is referencing.

However, I realized that the year cannot be included as the year was not displayed in the ls -ltc command.

Some people suggested finding the date /etc was created and some checking the /var/log/syslog etc. I thought these might be a little specific to the distro.

What is your recommendation for a truly distro-agnostic way to find the OS install date?

Best Answer

If the assumption is that you have an ext{2,3,4} filesystem, and you formatted the root filesystem when you installed the OS (and didn't do upgrades from another OS without a wipe), you can use dumpe2fs:

% dumpe2fs -h /dev/mapper/vg_desktop-lv_root 2>&1 |grep 'Filesystem created'
Filesystem created:       Sat Jul 23 04:28:07 2011
Related Question