169

is there a command which will output the date that ubuntu (or any distribution) was installed?

muru
  • 193,181
  • 53
  • 473
  • 722
lxtips
  • 1,791
  • 2
  • 11
  • 5

11 Answers11

154

You can check the installer logs and dates at:

/var/log/installer

A quick way to find the date through the command line would be by running:

ls -lt /var/log/installer

That lists in reverse chronological order so the oldest file is at the bottom of the list.

H2ONaCl
  • 9,513
  • 28
  • 73
  • 109
João Pinto
  • 17,029
  • 5
  • 55
  • 68
  • 3
    This file isn't on my Lucid system. – richq Aug 07 '10 at 20:31
  • On my system, I have 7 files under /var/log/installer/ . I installed from 9.10, and later updated to 10.04. – Stefan Lasiewski Aug 10 '10 at 00:34
  • I do also have this folder on my (freshly installed) 10.04 system and the creation dates of those files give me the install date. The file /var/log/installer/media-info for example contains the information about the installation media that was used for the install. – Marcel Stimberg Aug 10 '10 at 12:29
  • 1
    On my system that was installed originally with 7.10, `/var/log/installer/version` has a date of 2007-10-30, so this seems to be quite reliable... – JanC Oct 21 '10 at 03:02
  • 13
    A pastable answer might be `ls -ld /var/log/installer`. – Justin Force May 29 '12 at 21:45
  • `var/log/installer` Not present in my 12.04 Desktop – Chirag Aug 21 '12 at 19:42
  • I used "nano /var/log/installer/media-info" and found the date!!! – PHP Learner Nov 11 '13 at 08:13
  • **Note:** this file is not present in a `chroot` created by `debootstrap`. – Nathan Osman Aug 04 '15 at 22:55
  • Justin Force, `ls -ld /var/log/installer` as you know prints the directory date but on my system there is a file named `casper.log` that has a timestamp that is 54 minutes previous. If it is not only the date but also the time that is sought then `ls -lt /var/log/installer` would show the files in time order, making it easy to see the oldest file. – H2ONaCl Jan 06 '17 at 22:56
  • PHP Learner: `nano /var/log/installer/media-info` does not show the installation date. It shows the date the operating system image was created at Canonical. – H2ONaCl Jan 06 '17 at 23:00
  • cool! But I am confused, there are 7 files in this directory, each of them have the same date of 3rd July 2016, but one of them (the syslog file) has the date of 15th July 2016 - I cannot remember exactly how the installation run, but I doubt it ran 12 days :D - anyone knows what this difference means? – Nicolas Oct 27 '18 at 11:07
  • @joão-pinto `ls: cannot access '/var/log/installer': No such file or directory` – SebMa Aug 17 '22 at 08:03
98

If you use ext2/ext3/ext4 and formatted the disk when you installed you can do this nifty trick.

sudo dumpe2fs /dev/sda1 | grep 'Filesystem created:'

You might have to change the /dev/sda1 to reflect your setup.

Example output

Filesystem created: Fri Oct 14 22:40:09 2022

Relying on the date of files, even the "creation time" (mtime) can give errors since upgrading packages might have replaced the file and made a new "creation time".

Similar tools and info might be available on other file systems as well, but I don't know of them.

Zanna
  • 69,223
  • 56
  • 216
  • 327
LassePoulsen
  • 14,517
  • 8
  • 47
  • 59
21

the only command that worked for me is -

sudo ls -alct /|tail -1|awk '{print $6, $7, $8}'
Tim
  • 32,274
  • 27
  • 118
  • 177
Tony Doyle
  • 361
  • 2
  • 3
  • 3
    In my system, and I believe in everyone's, this is the creation date of `/lost+found` – MestreLion May 12 '22 at 09:39
  • Wow that's an smart workaround @MestreLion (for non-boot disks too). – Sridhar Sarnobat Nov 01 '22 at 23:38
  • 2
    @SridharSarnobat, credit for the cleverness goes to the answer, not to myself: that command prints the creation date of the oldest file/dir entry in the root directory. I simply stated that this is most likely `/lost+found`. Just notice this is for EXT4 filesystems: non-boot/root disks might be FAT/NTFS and thus have something else as the oldest entry. – MestreLion Nov 04 '22 at 21:53
  • 1
    `ls -ldsr /media/*/*/lost+found` for the impatient – Sridhar Sarnobat Nov 09 '22 at 21:06
  • Unfortunately even this answer may be misleading, for cloud services. They may have an image they created beforehand. – j riv Nov 22 '22 at 10:25
5

If the installation is recent, look at the oldest entries under /var/log, but after a few weeks the logs will have been rotated away.

Another thing to look at is the oldest ctime of a file on the root filesystem; but if the whole installation has been copied (e.g. rescued off a failing disk) at the directory tree level, this gives you the date of the copy.

If a heuristic is good enough, look at the date (mtime) of a file that was created during the installation and is unlikely to have been modified since. A good candidate is /etc/hostname; other candidates are /etc/hosts, /etc/papersize, /etc/popularity-contest.conf.

Gilles 'SO- stop being evil'
  • 59,745
  • 16
  • 131
  • 158
3

I also don't know of a specific command or file. I'm using some heuristics to find the installation date:

for dir in {/etc,/usr,/lib}; do
  sudo find $dir -type f -exec stat -c %z {} \; | \
    sed -e 's,-,,g' -e 's, .*,,' | sort | uniq -c | sort -nr -k 2 | \ 
    grep -Ev " [0-9]?[0-9] "
done

This small script looks for files in /etc and /usr and prints out the last changed date. It does some reformatting and lists the occurrences sorted by date (newest first). Usually the oldest entry is the installation date.

This assumes that after an installation are left unchanged. This is in most cases (according to my observation) true, but in special cases it can also give wrong results.

qbi
  • 18,879
  • 9
  • 79
  • 127
  • 1
    tried it on /etc only (faster), the date was the same as from the dumpe2fs solution, so for me it worked well! – eik3 Feb 28 '14 at 15:52
1

Unfortunately most answers can be misleading for cloud services because they often have an image they created beforehand.

In that case the best bet might be delving inside /var/log files and finding evidence of your own earliest boots.

Logs themselves may be from the image so you might need logs or file/dir creation dates unique to you.

j riv
  • 111
  • 3
1

For my Linux Mint system the following worked:

    sudo grep 'RTC time' /var/log/installer/syslog

The problem was my syslog didn't show years in the time stamps.

Mr Jacques
  • 171
  • 1
1

The command sudo grep ubiquity /var/log/installer/syslog | less worked for me very well.

Eliah Kagan
  • 116,445
  • 54
  • 318
  • 493
Bakhtiyor
  • 12,124
  • 25
  • 65
  • 81
0

I don't think there is.

On Red Hat / CentOS there is the install.log files that is generated when you install the system, but this doesn't exist on Ubuntu.

Assuming your logs go back far enough ( mine do ) you can determine the date the base installation was done in /var/log/dpkg.log*

For example on my system the first two lines of my oldest dpkg.log file (dpkg.log.4.gz) are

2010-04-19 11:40:55 startup archives install
2010-04-19 11:40:55 install base-files <none> 5.0.0ubuntu18

So I installed this system on 19/04/2010 at 11:40:55. That is correct for this system.

There was also a brainstorm idea to add this born date.

Richard Holloway
  • 29,974
  • 7
  • 52
  • 57
  • Thank-you andol, thank-you Richard. /var/log/dpkg.log.1 on a lucid desktop system gave a correct answer where as /var/log/dpkg.log was the only file on a lucid server setup I have, so a little detective work was needed. Some further understanding of the log files will be helpful. – lxtips Aug 06 '10 at 07:05
  • The default setup of `logrotate` discards dpkg logs older than one year. – LassePoulsen Aug 10 '10 at 12:13
  • @Source Lab : Yup. My answer is not foolproof. I did not know about the /var/log/installer directory but do now. That is a better solution. – Richard Holloway Aug 10 '10 at 17:20
  • I still think that the filesystem creation time is the best pointer se [here](http://ubuntu.stackexchange.com/questions/1352/date-ubuntu-was-installed/1843#1843) – LassePoulsen Aug 10 '10 at 17:31
0

You can type this :

$ \ls -lact --full-time / | awk 'END {print $6,substr($7,1,8)}'
2021-09-08 18:15:47

Or if you have ext2/3/4 filesystem on the / partition, you can type this :

$ sudo tune2fs -l $(findmnt -n -o source -T /) | awk '/created:/{$1=$2="";print substr($0,3)}'
Wed Sep 8 18:15:47 2021

Or if the directory /var/log/installer still exists :

$ \ls -lact --full-time /var/log/installer | awk 'END {print $6,substr($7,1,8)}'
2020-12-27 14:38:45
SebMa
  • 2,081
  • 3
  • 28
  • 38
0

would it be simple (i may be wrong) just to check software centre, while in there click on 'history' and scroll down to the bottom of your installed updates. Mine shows april 23 2012 first installation. Which is about right when I started using ubuntu?

maple6661
  • 11
  • 1