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

前端 未结 1 1095
灰色年华
灰色年华 2021-02-19 17:03

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 multipl

1条回答
  •  Happy的楠姐
    2021-02-19 17:27

    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
    

    0 讨论(0)
提交回复
热议问题