How to loop all files in sorted order in Bash?

后端 未结 7 1041
离开以前
离开以前 2020-12-05 01:51

I am looping all files in directory with following command:

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

However, I get order like this:

<         


        
7条回答
  •  伪装坚强ぢ
    2020-12-05 02:37

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

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

    The same using only ls:

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

提交回复
热议问题