As many of you know
uname -r returns the kernel release while
uname -v returns the version (build flags, date).
I'm trying to figure out a way to get an output of ONLY the release and the build date like
4.10.0-37-generic Fri Oct 6 22:42:22 UTC 2017
If I use
uname -rv I get
4.10.0-37-generic #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:22 UTC 2017
So what I need here is to find a pattern to remove the
#41~16.04.1-Ubuntu SMP. The only restrictions for a solution are:
- it has to be executable in a single line
- the locale of the system is US (or other English locale where the days of the week and month are printed in English)
- it has to be Linux distro- and distro-family-independent solution. That is why I went for
unamesince as far as I know this is a most basic tool that is present on all Linux distros - Debian, Red Hat, Slackware, Arch etc. Other tools can be used if they are present on "all" distros out there
- emphasis is on Linux, which means that BSD solutions (including MacOS) are not relevant.
The problem is that I'm not familiar with the command and especially if the way the date is printed is uniform that is I have considered simply removing the string after the first space (from left to right) until the sixth space (included, from right to left) but this will work ONLY if the date consists of 5 spaces:
<day of the week> <month> <day of the month> <daytime (HH:MM:SS)> <time standard/time zone> <Year>
Another thing I have considered is using mutual exclusion between the output from
uname -rv and
Linux version 4.10.0-37-generic (buildd@lcy01-30) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.4) ) #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:22 UTC 2017 |_______________| |_________________________| 4.10.0-37-generic #41~16.04.1-Ubuntu SMP Fri Oct 6 22:42:22 UTC 2017 |_______________| |_________________________|
Regular expression should be an option here too however as I've mentioned above I don't know if the format of the date is uniform hence making of regular expression is quite difficult (imho). To this we can also add the varying nature of
uname -v where the substring between the
# and the date can be very different from one system to another.