How can I sort file names by version numbers?

前端 未结 7 1185
轮回少年
轮回少年 2020-12-05 13:23

In the directory \"data\" are these files:

command-1.9a-setup
command-2.0a-setup
command-2.0c-setup
command-2.0-setup

相关标签:
7条回答
  • 2020-12-05 14:15

    Looks like this works:

    find /data/ -name 'command-*-setup' | sort -t - -V -k 2,2
    

    not with sort but it works:

    tree -ivL 1 /data/ | perl -nlE 'say if /\Acommand-[0-9][0-9a-z.]*-setup\z/'
    

    -v: sort the output by version
    -i: makes tree not print the indentation lines
    -L level: max display depth of the directory tree

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