What sort order does Linux use?

My Bash script runs files in a folder in alphabetical order. But it turns out that this is not the order that I have in the Mac OS folder. So now I am wondering what sorting order Linux uses, and can it be changed? Can I change it only for my bash script? Say I want to run a video player in a Bash script by running all the videos in a folder in alphabetical order, can I indicate in the script what alphanumeric order it should be?

+4
source share
1 answer

The sort order for many teams (including bashglob, ls, sort) is based on your current locale settings.

You can force the mapping by setting the environment variable LC_COLLATE. Setting it to C will perform a comparison by byte values.

On my system (en_US.utf8):

sh$ touch eleve
sh$ touch élève
sh$ touch Eleve 
sh$ touch Élève
sh$ touch äkta
sh$ touch österreich

sh$ ls
äkta  eleve  Eleve  élève  Élève  österreich  pommes

sh$ LC_COLLATE=fr_FR.utf8 ls
äkta  eleve  Eleve  élève  Élève  österreich  pommes

sh$ LC_COLLATE=sv_SE.utf8 ls
eleve  Eleve  élève  Élève  pommes  äkta  österreich

sh$ LC_COLLATE=C ls
Eleve  eleve  pommes  Élève  äkta  élève  österreich
+6
source

All Articles