I want a linux command that will return a unique identifier that would be generated at boot time

I am aware of the UUID and uname but there is no unique identifier for every time a system boots up.
There are security reasons why I want this.
The command should include the UUID, the kernel(uname) and a random identifier of boot.
I presume this should only be run by root.
I can do this myself with a bit of work but thought it should be part of linux.
I did not want to bother Linus

Try this:

date +"%s"

It will display the seconds since the epoch. Guaranteed different on every boot.
This , together with a unique hardware ID like primary NIC MAC will make it truely unique.

You can even extend it to nanoseconds (a bit overkill for this case though):

date +"%s%N"
  1. Are you sure you want the UUID of the drive that is mounted as rootfs ?
  2. With 'uname' you mean 'uname -r' ?

Hmm, okay .... In that case, try this:

echo "$( { lsblk -no UUID "$( df |grep '/$' |cut -d\  -f1 )" ; uname -r ; date +"%s" ;} | tr -d "\n" )"

Don't expect exceptionally rare usecases to be implemented as a standard command in any OS.

The good thing of the Linux (POSIX) shells is that in these exceptional cases a oneliner can save the day :slight_smile:


do you really believe Linus T. would reply? As @tkn mentioned, this is an extreme use case.


I will let you cogitate as to the reasons why I would want such information and its uses.
The UUID is relatively constant as is the kernel in time. The solution given by @tkn above is quite neat but very variable and not system resident unless saved to disk or emailed out.
I imagine when Linus first thought of Linux people could have said "this is an extreme use case"
Let one not be limited by the imagination of others

you need to generate entropy to your linux system, here's a link

1 Like