I have some trouble to understand what is happening here:
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="5631233f3239163a3935373a3e392522">[email protected]</a> 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
IIIb before Ib, but IIb before IIIb? Whatever is causing this, it is not behaving consistently. This is also the same sorting result I get in the GUI. I checked all the blanks are actually blanks, and there are no case difference among the filenames. How can it be? Is it skipping the roman numeral, and trying to sort after it?
Other tests:
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="0364766a676c436f6c60626f6b6c7077">[email protected]</a> 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
But:
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="3750425e5358775b5854565b5f584443">[email protected]</a> 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
While:
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="1374667a777c537f7c70727f7b7c6067">[email protected]</a> 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
I don’t think my locale may be affecting this (I also set it to en_US.utf8 anyway) as the doc suggests. What am I missing?
[<a href="https://getridbug.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="87e0f2eee3e8c7ebe8e4e6ebefe8f4f3">[email protected]</a> 9]$ sort --version sort (GNU coreutils) 8.22
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
Spaces (and probably case) are ignored when sorting with your locale. Thus you have this ordering after the common prefix “Star Wars Episode”:
- IIA
- III
- ITH
The find returns results in directory order, which just happens to be the “expected” order.
You can return to “traditional” sorting per this from the man page:
Set LC_ALL=C to get the traditional sort order that uses native byte values.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0