How can I sort file names by version numbers?

前端 未结 7 1200
轮回少年
轮回少年 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:10

    I have files in a folder and need to get those name in sort order, based on the number. E.g. -

    abc_dr-1.txt
    hg_io-5.txt
    kls_er_we-3.txt
    sd-4.txt
    sl_rt_we_yh-2.txt
    

    I need to sort them based on number. So I used this to sort.

    ls -1 | sort -t '-' -nk2
    

    It gave me files in sort order based on number.

提交回复
热议问题