Want to know when your Linux system was installed? Don’t wonder anymore! Here’s how to do it quickly with a single simple command.
Have you ever found yourself pondering the age of your Linux system? Perhaps you’ve inherited a computer or are curious about when you first set up your trusty Linux machine.
In this article, we’ll show you a straightforward and efficient method to uncover the installation date of your Linux system using just a single command.
So, let’s embark on this short journey, and you’ll soon have a clear answer to the question, “When was my Linux system installed?”
Find Date and Time Linux OS Was Installed
Finding this information can be done in many different ways, and below, we present you with the best ones, both valid for any Linux distribution and specific to a particular one.
A Universal Method
First, we must clarify that there is no dedicated setting, variable, log file entry, or similar in Linux designed to expressly store information about the actual day and time when the system was installed.
However, it can be easily retrieved by determining when the root (“/”) file system was created.
This can be accomplished with the help of the stat
command, which displays detailed information about a file or directory, including metadata such as create, access, and modification timestamps, file type, permissions, and more.
So, to find the exact day and time when your Linux system was installed, run the following:
stat / | awk '/Birth: /{print $2 " " substr($3,1,5)}'
And that’s all! We get the information we need right away. According to the command’s output above, the system was installed on December 22, 2020, at 2:14 AM.
In the above example, to display in a convenient way only the information we need, we have piped the stat
command’s output to the awk
and further formatted it using the substr
function.
However, if you want to keep things as simple as possible, you can run the stat
command below and look at the “Birth” row, indicating the moment the item was created on the file system.
stat /
Need more details? Check the stat
command man page.
Another alternative approach to get information about when the file system was created, which is the Linux system’s installation time, is to use the command below. Remember that you must switch to the root user before running it.
fsname=$(df / | tail -1 | cut -f1 -d' ') && tune2fs -l $fsname | grep 'created'
Of course, other ways exist to discover when the Linux operating system was installed. Still, unlike the distro-agnostic ones shown above, they are tied to the particular distribution used. Here they are.
Debian / Ubuntu
On Debian and Ubuntu systems and all their derivatives like Linux Mint and others, you can see the exact day and time they were installed by displaying the first line of the installer syslog file.
sudo head -n1 /var/log/installer/syslog
RHEL / Rocky Linux / AlmaLinux
In Red Hat Enterprise Linux and all its forks, such as Rocky Linux, AlmaLinux, Oracle Linux, etc., we can use it as a reliable marker of when the operating system was installed by checking the installation date of the “basesystem” package.
sudo rpm -qi basesystem | grep -i "install date"
Arch Linux
If you’re running Arch or one of its derivatives like Manjaro or EndeavourOS, the first line of the “pacman.log” file will tell you when your Linux system was installed.
head -n1 /var/log/pacman.log
Bottom Line
The quest to determine the installation date of your Linux system need not be shrouded in uncertainty any longer. Using the methods outlined in this guide, you can swiftly and effortlessly unveil your Linux system’s birthdate.
So, when is your Linux system installed? We can’t wait for you to let us know in the comments below.
Dear sir,
Your command
stat / | awk ‘/Birth: /{print $2 ” ” substr($3,1,5)}’
will succeed only and only if you know in advance
that the string “Birth” is inside the return of stat.
But if your system is French, Italian, Spanish, etc…
your command will not succeed.
For a system with french, the following command will succeed:
stat / | awk ‘/Créé/{print $2 ” ” substr($3,1,5)}’
Gérard
On my Rocky 9.2 system:
The first recipe returns “2023-03-07 23:47”
The one using stat returns the same value.
the second one returns: fsname=$(df / | tail -1 | cut -f1 -d’ ‘) && tune2fs -l $fsname | grep ‘created’
tune2fs: Permission denied while trying to open /dev/md125
Couldn’t find valid filesystem superblock.
the one using RPM (I’m using Rocky Linux 9.2) returns:
sudo rpm -qi basesystem | grep -i “install date”
Install Date: Thu 24 Nov 2022 01:46:00 AM EST
You will note that 2023-03-07 23:47 is not even in the same neighborhood as Thu 24 Nov 2022 01:46:00 AM EST. I would guess that the ‘install date’ field refers to some other event, maybe something to do with the creation of the installable image?
I will assume that the failure of the one using tune2fs has to do with / being on a Linux Raid member rather than an actual partition.
Fred