加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 如何按版本号排序文件名?

发布时间:2020-12-15 18:48:17 所属栏目:安全 来源:网络整理
导读:目录“数据”是这些文件: command-1.9a-setup command-2.0a-setup command-2.0c-setup command-2.0-setup 我想对文件进行排序以获得此结果: command-1.9a-setup command-2.0-setup command-2.0a-setup command-2.0c-setup 我试过了 find /data/ -name 'com
目录“数据”是这些文件:

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

我想对文件进行排序以获得此结果:

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

我试过了

find /data/ -name 'command-*-setup' | sort --version-sort --field-separator=- -k2

但产量是

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

我找到的唯一方法是给我我想要的输出

tree -v /data

我怎么能按需要的顺序排序输出?

如果你指定排序,你只想考虑第二个字段(-k2)不要抱怨它不考虑第三个字段.

在你的情况下,运行排序–version-sort没有任何其他参数,也许这将适合更好.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读