A while back I built my friend a fairly simple custom application for his business. It was just a web front end with a MySQL database and never meant for long term use. However, I just spoke with him and he said it was still running. He also mentioned that the only time he ever touched the server was about 2 years ago when there was a power outage. I was amazed and wondered just how long it has been since I brought the server online. I needed a way to find the date and time of the OS installation (I am just a curious person). If you are also a curious person you are probably wondering how long the server was running? Keep reading to find out how to find the date and time Linux OS was installed, as well as how long my buddies system has been running with zero maintenance or updates.
Use stat Command to Find OS Installation (Birth) Date and Time
You can use the stat command to display important information about files. Here we use the stat command to show us the birth date and time of the root filesystem.
[root@scoreboard savona]# stat -c %w /
2017-10-15 17:18:29.072261178 -0400
The stat command is part of the GNU Core Utilities package and is pre-installed on just about every Linux system.
Get Linux OS Installation Date and Time with basesystem
This trick only works on Fedora, Red Hat, CentOS etc... The basesystem package stores information about the system. One of these pieces of information is the OS Installation date. Here is an example of how to use the rpm
command to get information from basesystem.
[root@scoreboard savona]# rpm -qi basesystem | grep "Install Date"
Install Date: Sun 15 Oct 2017 05:18:45 PM EDT
Find Linux Installation Date and Time from Anaconda Files
Another option is simply finding when the anaconda-ks.cfg
file was created. This file is automatically created to save your installation settings.
[root@scoreboard savona]# ls -l /root/anaconda-ks.cfg
-rw-------. 1 root root 1507 Oct 15 2017 /root/anaconda-ks.cfg
Using Logs to Find Linux Installation Date and Time
There are also some logs that you can use to find the date. Here we use the stat comand again to see the birth of the anaconda.log file.
[root@scoreboard savona]# ls -l /var/log/anaconda*
total 4208
-rw-------. 1 root root 191556 Oct 15 2017 anaconda.log
...OUTPUT TRUNCATED...
[root@scoreboard savona]# stat /var/log/anaconda/anaconda.log
File: ‘/var/log/anaconda/anaconda.log’
...OUTPUT TRUNCATED...
Birth: 2017-10-15 17:18:29.744882572 -0400
Again, the above will only work on Fedora/Red Hat systems because they use the Anaconda installer. However, I am sure whatever Linux distro you use, you will find a similar file.
Conclusion
There are plenty of ways to the find the time and date of your Linux OS installation. We just showed you a few quick ways starting with the most widely available, the stat command. As always please feel free to leave a comment and tell us how you would find it!
BTW, it looks like my friends server was running for a total of 1579 days (just over 4 years) with no updates, patches, or human intervention. Interesting...