ls -v ./file*
按自然顺序对文件名进行排序:
file1.txt
file2.txt
file11.txt
但如果我们包含负数,则会回馈:
file1.txt
file2.txt
file11.txt
file-5.txt
file-18.txt
如何按自然顺序排序,包括负数?
答案 0 :(得分:1)
似乎有以下作用:
$ ls file*|sort -k1.5n #start sorting at character 5
file-18.txt
file-5.txt
file1.txt
file2.txt
file11.txt
要测试,请执行:
echo "a black" > file-18.txt
echo "e white" > file-5.txt
echo "i red" > file1.txt
echo "o green" > file2.txt
echo "u blue" > file11.txt
echo "voyelles" > file013.47.txt
ls file*|sort -k1.5n #start sorting at character 5