我很难理解这里发生的事情:
[guido@localhost 9]$ ls -1 Star\ Wars\ Episode\ *
Star Wars Episode II Attack of the Clones.avi
Star Wars Episode III Revenge of the Sith.avi
Star Wars Episode I The Phantom Menace.avi
Star Wars Episode IV A New Hope.avi
Star Wars Episode VI Return of the Jedi.avi
Star Wars Episode V The Empire Strikes Back.avi
III\b
之前I\b
,但是II\b
之前III\b
?无论是什么原因造成的,它的行为都不一致。这也与我在 GUI 中得到的排序结果相同。我检查了所有的空白实际上都是空白,并且文件名之间没有大小写差异。怎么会这样?它是否跳过罗马数字并尝试对其进行排序?
其他测试:
[guido@localhost 9]$ find -name "Star Wars *" -print
./Star Wars Episode I The Phantom Menace.avi
./Star Wars Episode II Attack of the Clones.avi
./Star Wars Episode III Revenge of the Sith.avi
./Star Wars Episode IV A New Hope.avi
./Star Wars Episode V The Empire Strikes Back.avi
./Star Wars Episode VI Return of the Jedi.avi
但:
[guido@localhost 9]$ find -name "Star Wars *" -print | sort
./Star Wars Episode II Attack of the Clones.avi
./Star Wars Episode III Revenge of the Sith.avi
./Star Wars Episode I The Phantom Menace.avi
./Star Wars Episode IV A New Hope.avi
./Star Wars Episode VI Return of the Jedi.avi
./Star Wars Episode V The Empire Strikes Back.avi
尽管:
[guido@localhost 9]$ find -name "Star Wars *" -print | sort -f
./Star Wars Episode I The Phantom Menace.avi
./Star Wars Episode II Attack of the Clones.avi
./Star Wars Episode III Revenge of the Sith.avi
./Star Wars Episode IV A New Hope.avi
./Star Wars Episode V The Empire Strikes Back.avi
./Star Wars Episode VI Return of the Jedi.avi
我不认为我的语言环境可能会影响这一点(无论如何我也将其设置为 en_US.utf8),正如文档所建议的那样。我缺少什么?
[guido@localhost 9]$ sort --version
sort (GNU coreutils) 8.22
答案1
根据您的语言环境进行排序时,空格(可能还有大小写)将被忽略。因此,您可以在公共前缀“Star Wars Episode”之后进行以下排序:
- 国际投资协会
- 三、
- 信息技术研究所
返回find
结果按目录顺序排列,这恰好是“预期”顺序。
您可以根据此返回到“传统”排序手册页:
设置 LC_ALL=C 以获取使用本机字节值的传统排序顺序。