Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I select the filename with the highest version number?

Tags:

bash

I wrote a build script and would like to be able to select the latest version of the script when it installs, e.g. the package name is package_X.X.X.tar.gz and there are multiple copies.

Is there a way to point the build command to package_Y.tar.gz? where Y=max(X.X.X)?

like image 223
David LeBauer Avatar asked Nov 03 '10 14:11

David LeBauer


1 Answers

If the files are equal except for the version numbers, you could use something like

ls -v | tail -n 1

From the man-page of ls:

...
-v     natural sort of (version) numbers within text
...

Example usage:

$ ls
package_1.5.7.9.tar.gz  package_2.5.3.9.tar.gz  package_4.6.1.0.tar.gz
$ ls -v | tail -n 1
package_4.6.1.0.tar.gz
like image 190
aioobe Avatar answered Oct 20 '22 01:10

aioobe