如何使用bash对文件夹中的文件进行排序?

wak*_*dan 5 linux sorting bash shell

我将这些文件放在一个文件夹中:

chap11-solutions.pdf
chap12-solutions.pdf
chap13-solutions.pdf
chap14-solutions.pdf
chap15-solutions.pdf
chap16-solutions.pdf
chap17-solutions.pdf
chap21-solutions.pdf
chap22-solutions.pdf
chap23-solutions.pdf
chap24-solutions.pdf
chap25-solutions.pdf
chap26-solutions.pdf
chap2-solutions.pdf
chap3-solutions.pdf
chap4-solutions.pdf
chap5-solutions.pdf
chap6-solutions.pdf
chap7-solutions.pdf
chap8-solutions.pdf
chap9-solutions.pdf
Run Code Online (Sandbox Code Playgroud)

我如何以这种方式对它们进行排序:chap1 ...,chap ... 2,....,chap11 ...,chap12,...使用Ubuntu bash shell?谢谢.

Arn*_*anc 24

ls|sort -V
Run Code Online (Sandbox Code Playgroud)

-V参数确保chap10被认为是上限chap9.

  • 请注意,`-V`选项仅适用于相对较新的GNU coreutils - 它不适用于5.93(Mac OS 10.6默认发布的那个). (2认同)

Pau*_*ce. 8

GNU ls内置了一个版本排序:

ls -lv
Run Code Online (Sandbox Code Playgroud)