1

Let us suppose that there is a command such as:

# uname -a
Linux (none) 2.6.24 #155 PREEMPT Thu Nov 16 09:41:07 IST 2017 ppc GNU/Linux

Now, my question is: Are there any commands which will only print:

Nov 16 09:41:07 IST 2017

And could you please explain the command a little? Thank you! in advance.

  • 3
    Not sure what your application is. Are you looking for a command to extract 7th to 11th fields (delineated by blanks) of a line or are you asking to search a line to find a date, or are you asking to get the date of the kernel, or is this a homework assignment and your instructor lacks imagination and clear instructions? – WinEunuuchs2Unix Jan 16 '18 at 4:48
  • Has any of the answers helped you? Please accept it or clarify your needs using editing or comments. – Melebius Jan 24 '18 at 7:35
0

This awk will do that using this variable:

uname -a | awk '{ print $7,$8,$9,$10,$11 }'

Result:

Nov 16 09:41:07 IST 2017
  • awk: start awk program
  • '{ print $7,$8,$9 }': print the 7th, 8th and 9th fields with , spaces between these values.
  • uname -a |: pipe the result of uname -a to the awk command for processing
  • This does not work in my case where the field count differs. uname -a gives Linux MiM-testsrv-ubuntu 4.4.0-72-lowlatency #93-Ubuntu SMP PREEMPT Fri Mar 31 15:14:04 UTC 2017 i686 i686 i686 GNU/Linux, the result of your command: Fri Mar 31 15:14:04 UTC – Melebius Jan 16 '18 at 7:43
  • This is not a one-to-one support site but a public knowledge base, so we should post universally usable answers. If they have some caveats, we should warn about them. – Melebius Jan 16 '18 at 7:55
  • Melebius Now, why would you assume OP wants to use the command uname -v rather than uname -a perhaps you know the OP? I don't second guess OPs I do as requested and add any extra for the general public. – George Udosen Jan 16 '18 at 8:07
  • As WinEunuuchs2Unix correctly pointed out, the question is ambiguous. You chose one option from the possibilities mentioned by WinEunuuchs2Unix, I chose another. Hopefully, OP will come back and clarify their needs. In the meantime (which may also grow to infinity), we should clarify the assumptions valid for our solutions. – Melebius Jan 16 '18 at 9:21
0

The command uname -a prints all the information about your kernel while uname -v only prints kernel version which is the part ending with the date:

$ uname -v
#155 PREEMPT Thu Nov 16 09:41:07 IST 2017

You can use the tail -c command to print the end of the string with the specified length.

uname -v | tail -c25

This works well also in my case where the count of spaces differs.

$ uname -v
#93-Ubuntu SMP PREEMPT Fri Mar 31 15:14:04 UTC 2017
$ uname -v | tail -c25
Mar 31 15:14:04 UTC 2017
  • And what is the result of uname -a | tail -c25 as I see OP used uname -a and not uname -v. Please direct your questions to Op to clarify any ambiguities! – George Udosen Jan 16 '18 at 8:10
  • @GeorgeUdosen I had explained it in the beginning of my answer. I’ve just added a bit more information, please check it now. – Melebius Jan 16 '18 at 9:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.