How find Linux version from command line?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How find Linux version from command line?
# 1  
Old 09-01-2014
How find Linux version from command line?

Hi,

I am looking to extract linux version from /etc/*-release file.

I am specifically tring to avoid use of awk command here. would be great if can do done via sed or grep command.

Red Hat Enterprise Linux Server release 6.5 (Tikanga)

output must be 6

regards,
Litu
# 2  
Old 09-01-2014
Hello Litu,

Kindly use the code tags for commands and codes which you are using in the posts, also you can review your post before click on Submit Reply by clicking on Preview Post. Following may be helpful for you.

Code:
awk '{print $(NF-1)}' /etc/redhat-release

This should show the version of Linux Server release.

Thanks,
R. Singh
# 3  
Old 09-01-2014
thanks for the reply. But we are trying to avoid use of awk command. can we do the same using grep, sed or cut command.
# 4  
Old 09-01-2014
Hello Litu,

Following sed solution may help you.

Code:
sed 's/[[:alpha:]]//g;s/[[:space:]]//g' filename

EDIT: Adding more solutions for same.

Code:
cut -f7 -d " " /etc/redhat-release | cut -c1
 
cut -f7 -d " " /etc/redhat-release | cut -f1 -d"."

Thanks,
R. Singh

Last edited by RavinderSingh13; 09-01-2014 at 08:52 AM.. Reason: Added filename + added more solutions with cut now
This User Gave Thanks to RavinderSingh13 For This Post:
# 5  
Old 09-01-2014
Both the codes give you 6 as the output
Code:
rev /etc/redhat-release | cut -f2 -d ' ' | rev | cut -f1 -d '.'

of
Code:
cut -f1 -d '.' /etc/redhat-release | rev | cut -f1 -d ' ' | rev

---------- Post updated at 07:54 AM ---------- Previous update was at 07:49 AM ----------

sed solution
Code:
sed 's/[^[:digit:]]*\([[:digit:]]*\)\..*/\1/' /etc/redhat-release


Last edited by SriniShoo; 09-01-2014 at 09:01 AM.. Reason: missed sed, thanks to Ravinder
# 6  
Old 09-01-2014
Posted by SriniShoo:

Quote:
Both the codes give you 6 as the output


Code:
rev /etc/redhat-release | cut -f2 -d ' ' | rev | cut -f1 -d '.'

of


Code:
cut -f1 -d '.' /etc/redhat-release | rev | cut -f1 -d ' ' | rev
Hello SriniShoo,

I am not sure why you are using rev here, I guess we can esaily do it with cut and sed.


EDIT: Also you have missed sed while giving sed solutions.
Quote:
Both the codes give you 6 as the output

Code:
rev /etc/redhat-release | cut -f2 -d ' ' | rev | cut -f1 -d '.'

of


Code:
cut -f1 -d '.' /etc/redhat-release | rev | cut -f1 -d ' ' | rev

---------- Post updated at 07:54 AM ---------- Previous update was at 07:49 AM ----------

sed solution


Code:
's/[^[:digit:]]*\([[:digit:]]*\)\..*/\1/' /etc/redhat-release
Code:
sed 's/[^[:digit:]]*\([[:digit:]]*\)\..*/\1/' /etc/redhat-release

Thanks,
R. Singh
# 7  
Old 09-01-2014
thanks a lot R Singh...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to find weblogic version in Linux?

Hi All, I am able to find the weblogic version in Centos 7 by using below command but i am not sure what is java -cp is doing in below command. Can someone please help. unable to find info from java man page as well. # cd /opt/oracle/weblogic/wlserver*/server/lib && java -cp... (1 Reply)
Discussion started by: sravani25
1 Replies

2. Shell Programming and Scripting

Linux find command seems to not transmit all the result to the '-exec command'

Hello. From a script, a command for a test is use : find /home/user_install -maxdepth 1 -type f -newer /tmp/000_skel_file_deb ! -newer /tmp/000_skel_file_end -name '.bashrc' -o -name '.profile' -o -name '.gtkrc-2.0' -o -name '.i18n' -o -name '.inputrc' Tha command... (3 Replies)
Discussion started by: jcdole
3 Replies

3. UNIX for Dummies Questions & Answers

To find and display the middle line in a file using single line command.

Hi all, How can i display the middle line of a file using a single line command? (6 Replies)
Discussion started by: Lakme Pemmaiah
6 Replies

4. Shell Programming and Scripting

How to find duplicate line in Linux?

Hi, Gurus, I need find the duplicate record in unix file. what command I should use for this. Thanks in advance (4 Replies)
Discussion started by: ken6503
4 Replies

5. Ubuntu

Download latest Ubuntu version from linux command

I have ubuntu 10.4 on my system and want to download newer Ubuntu version like 11.04. Is there any linux command(something like apt-get source used for downloading kernel source) using which I can download directly the newer ubuntu relaease? (2 Replies)
Discussion started by: rupeshkp728
2 Replies

6. UNIX Desktop Questions & Answers

Finding USB version on command line

Would anyone happen to know what to grep for finding the version of the USB ports are on the system through the command line? Thanks. (1 Reply)
Discussion started by: eightysix
1 Replies

7. Shell Programming and Scripting

unix command to find the version of Informix database

Hi All Please let me know if there is command to check the version of the informix database installed..? Thanks in advance. Suresh (4 Replies)
Discussion started by: sureshg_sampat
4 Replies

8. UNIX for Dummies Questions & Answers

Redhat linux command to check Version

Hi All, I need to know RedHat linux version installed on a different servers. I know uname -a or /proc/version Is any other command to know the Linux version???? When we telnet to any of the Linux server, the version shows very clearly like Red Hat Enterprise Linux ES release 3 (Taroon... (1 Reply)
Discussion started by: bache_gowda
1 Replies

9. Shell Programming and Scripting

using the perl version of the find command...

hi, i am looking through the perl documentation in the man pages for the first time but I have looked at some other reference giudes before (at a glance) and remember that there is a find command used by perl can any one give me a structured example of that command and how it works and if possible... (2 Replies)
Discussion started by: moxxx68
2 Replies

10. UNIX for Dummies Questions & Answers

Is there a linux version of dos2unix command?

I'm having some probs and i know in unix i can do a dos2unix command and fix it, and it looks like that may be my problem now, but linux doesn't have dos2unix of course, anything comparable? (4 Replies)
Discussion started by: kymberm
4 Replies
Login or Register to Ask a Question