Results 1 to 7 of 7
Hi all , i have the following situation, a directory contains something like :
linux v1r0p2
linux v3r7p2
linux v4r6p9
and so on, i want to write a script can ...
- 12-04-2007 #1
finding out last version with bash
Hi all , i have the following situation, a directory contains something like :
linux v1r0p2
linux v3r7p2
linux v4r6p9
and so on, i want to write a script can grab me the last version, i've done something, but it a bit complicated and long, i'm wondering if there is a combination of sed and awd can do it easily.Linux is not only an operating system, it's a philosophy.
Archost.
- 12-04-2007 #2Linux Newbie
- Join Date
- Nov 2007
- Location
- Planet Earth
- Posts
- 152
Code:ls -1 | sort -r | head -1

(only if the version strings have the same length... I think)EOF
- 12-04-2007 #3I use it like this and it seems it's working , thanks a lot .Code:
ls -l | grep -w 'linux' | sort -r | head -1
Cheers.Linux is not only an operating system, it's a philosophy.
Archost.
- 12-07-2007 #4Linux Enthusiast
- Join Date
- Aug 2006
- Location
- Portsmouth, UK
- Posts
- 539
If the latest version is always the last one created, add "t" to the ls command to sort by time as well, the "t" and "r" flags to ls imply sorting so you don't need to pipe it through the sort command:
Edit:Code:ls -ltr linux* | head -1
You don't need grep either...RHCE #100-015-395
Please don't PM me with questions as no reply may offend, that's what the forums are for.
- 12-07-2007 #5Linux is not only an operating system, it's a philosophy.
Archost.
- 12-07-2007 #6Linux Enthusiast
- Join Date
- Aug 2006
- Location
- Portsmouth, UK
- Posts
- 539
In that case drop the "t"...
RHCE #100-015-395
Please don't PM me with questions as no reply may offend, that's what the forums are for.
- 12-08-2007 #7Linux Engineer
- Join Date
- Feb 2005
- Posts
- 1,044
To be exactly equivalent, you'd need
since grep will match 'linux' anywhere in the name, not just at the beginning. And, of course, you don't need the -l if you only want the filename - remember that ls writes filenames one per line unless it's writing to a terminal (so you don't need the -1 (that's a one, not an L) that hugortega used in his example).Code:ls -lr *linux* | head -1
Also be aware that it'll break after v9 since v10 will sort after v1 but before v2.


Reply With Quote
