当我看到ls以奇怪顺序列出的下列文件时,我一直很困惑:
Star Wars Episode II - Attack of the Clones (2002) BDRip.mkv
Star Wars Episode III - Revenge of the Sith (2005) BDRip.mkv
Star Wars Episode I - The Phantom Menace (1999) BDRip.mkv
Star Wars Episode IV - A New Hope (1977) BDRip.mkv
Star Wars Episode VI - Return of the Jedi (1983) BDRip.mkv
Star Wars Episode V - The Empire Strikes Back (1980) BDRip.mkv
从人的角度来看,“我”应该先行,然后“行进”,等等.
$cat 1
Star Wars Episode II - Attack
Star Wars Episode III - Revenge
Star Wars Episode I - The
Star Wars Episode IV - A
Star Wars Episode VI - Return
Star Wars Episode V - The
如果我对它进行排序它会给我这个:
$sort 1
Star Wars Episode II - Attack
Star Wars Episode III - Revenge
Star Wars Episode I - The
Star Wars Episode IV - A
Star Wars Episode VI - Return
Star Wars Episode V - The
$cat 1
Star Wars Episode II
Star Wars Episode III
Star Wars Episode I
Star Wars Episode IV
Star Wars Episode VI
Star Wars Episode V
$sort 1
Star Wars Episode I
Star Wars Episode II
Star Wars Episode III
Star Wars Episode IV
Star Wars Episode V
Star Wars Episode VI
所以,只要我在空格后添加任何符号,它就会开始为我排序不可预测:
$cat 1
Star Wars Episode II y
Star Wars Episode III x
Star Wars Episode I z
Star Wars Episode IV w
Star Wars Episode VI v
Star Wars Episode V u
$sort 1
Star Wars Episode III x
Star Wars Episode II y
Star Wars Episode IV w
Star Wars Episode I z
Star Wars Episode VI v
Star Wars Episode V u
有关此排序行为的任何提示吗?
更新:排序:使用’en_CA.UTF-8’排序规则
根据下面的评论更新#2是因为语言环境.
ls | LANG=C sort
Star Wars Episode I - The Phantom Menace (1999) BDRip.mkv
Star Wars Episode II - Attack of the Clones (2002) BDRip.mkv
Star Wars Episode III - Revenge of the Sith (2005) BDRip.mkv
Star Wars Episode IV - A New Hope (1977) BDRip.mkv
Star Wars Episode V - The Empire Strikes Back (1980) BDRip.mkv
Star Wars Episode VI - Return of the Jedi (1983) BDRip.mkv
为什么然后UTF8语言环境使它与众不同?
我检查了ru_RU.UTF8(错误排序)和ru_RU.KOI8-R(正确排序)
更新#3这是关于语言环境:http://www.gnu.org/software/coreutils/faq/#Sort-does-not-sort-in-normal-order_0021
最佳答案