1

This has been an incredible annoyance for me because it should be so easy to fix!!! I want ASCII conventions to be applied when sorting files (both in the terminal and in nautilus) because the "intelligent" sorting algorithm is anything but in my opinion. There seem to have been fixes for older versions of Ubuntu (c. 2008) put out there, where setting "LC_COLLATE=C" supposedly fixes the problem (see here and here for details). However this emphatically fails to solve the issue that I am currently having. I am running Trusty (14.04) with the new 3.16 kernel.

For example, the ls command currently gives:

ME 702 - Computational Fluid Dynamics - Video Lesson 1(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 10(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 11(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 12(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 13(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 14(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 15(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 16(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 17(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 18(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 19(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 2(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 20(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 21(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 22(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 23(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 24(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 25(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 26(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 27(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 28(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 3(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 4(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 5(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 6(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 7(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 8(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 9(360p_H.264-AAC).mp4

When what I really want is

ME 702 - Computational Fluid Dynamics - Video Lesson 1(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 2(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 3(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 4(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 5(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 6(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 7(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 8(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 9(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 10(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 11(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 12(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 13(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 14(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 15(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 16(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 17(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 18(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 19(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 20(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 21(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 22(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 23(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 24(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 25(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 26(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 27(360p_H.264-AAC).mp4
ME 702 - Computational Fluid Dynamics - Video Lesson 28(360p_H.264-AAC).mp4

Any thoughts on how to get this working?

  • 1
    Perhaps this is a misunderstanding of ASCII sort? in ASCII, the sort is 1, 10, 11, 12,..., 2, 20, 21, ..., For my the solution has been (for 40 years) to use 01, 02, 03, ..., 09, 10, 11, 12, 13 – Charles Green Aug 7 '14 at 4:49
  • @CharlesGreen is correct. You should write it up as the answer. FWIW you can sort numerically with (e.g.) ls | sort -n -k 10, but this is pretty unwieldy. – Sparhawk Aug 7 '14 at 5:11
0

ASCII sorts are very basic, in that 1 comes before 2, and 2 before 3, and so on. So when I look at a simple list, 0, 1, 2, 3,... 8, 9 the characters are sorted in the same order as a numeric sort.

The problem somes with multi-digit numbers. Consider the list: 1, 10, 11, 2, 20

This is in fact sorted correctly as characters, but incorrectly as numbers. In the above list, the first character of the number "11" is a "1" which comes before a "2", just like "as" comes before "b".

Many of us would like files and columns of items to be sorted in a numeric sense rather than an ASCII sense - the easiest solution that I have, which is cumbersome, is to know in advance how many files I expect to have, and prepend the numbers with "0" to pad out the filenames to a correct length - thus my files would be named 001, 002, 003... 010, 011

You may insist that this is a contrived method of ordering the files by name, and I will agree! However you must also remember that ASCII stands for "American Standard Code for Information Interchange" and is nothing more than assigning a digital code to a character. In asking for a list to be sorted in an ASCII fashion, you are asking for a character sort.

| improve this answer | |
  • Any thoughts on modifying the LC_COLLATE (or similar) environment variable? This seemed to achieve the desired result on previous versions of Ubuntu. – Bryson S. Aug 7 '14 at 11:03

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.