如何在Bash中按排序顺序循环播放所有文件? [英] How to loop all files in sorted order in Bash?

查看:64
本文介绍了如何在Bash中按排序顺序循环播放所有文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下命令循环目录中的所有文件:

I am looping all files in directory with following command:

for i in *.fas; do some_code; done;

但是,我得到这样的订单:

However, I get order like this:

vvchr1.fas  
vvchr10.fas  
vvchr11.fas

什么是数字顺序,而不是vvchr1.fas,vvchr2.fas,vvchr3.fas.

Instead of vvchr1.fas, vvchr2.fas, vvchr3.fas, what is numerical order.

我尝试了排序命令,但没有成功.

I have tried sort command, but with no success.

推荐答案

for i in `ls *.fas | sort -V`; do some_code; done;

其中sort -V根据man sort进行版本排序-文本中自然的(版本)数字

where sort -V does according to man sort a version sort - a natural sort of (version) numbers within text

仅使用ls相同:

for i in `ls -v *.fas`; do echo $i; done;

这篇关于如何在Bash中按排序顺序循环播放所有文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆