Why are files listed alphabetically, ignoring file name length in the terminal?
Perhaps I shouldn't say "ignoring" file name length, but rather, why is there a difference in displaying files in the terminal vs. a GUI.
This is certainly a trivial question, but I've been a bit curious about this one for a while.
In the terminal, a vanilla ls
command using the -l
option (with no other sorting options specified) lists files in alphabetical order starting from the top line of the list moving down. Say I have a directory full of files created with the following:
$ touch file1{1..16}
ls
in that same directory would display the following:
-rw-r--r--. 1 user user 0 May 24 11:14 file1
-rw-r--r--. 1 user user 0 May 24 11:14 file10
-rw-r--r--. 1 user user 0 May 24 11:14 file11
-rw-r--r--. 1 user user 0 May 24 11:14 file12
-rw-r--r--. 1 user user 0 May 24 11:14 file13
-rw-r--r--. 1 user user 0 May 24 11:14 file14
-rw-r--r--. 1 user user 0 May 24 11:14 file15
-rw-r--r--. 1 user user 0 May 24 11:14 file16
-rw-r--r--. 1 user user 0 May 24 11:14 file2
-rw-r--r--. 1 user user 0 May 24 11:14 file3
-rw-r--r--. 1 user user 0 May 24 11:14 file4
-rw-r--r--. 1 user user 0 May 24 11:14 file5
-rw-r--r--. 1 user user 0 May 24 11:14 file6
-rw-r--r--. 1 user user 0 May 24 11:14 file7
-rw-r--r--. 1 user user 0 May 24 11:14 file8
-rw-r--r--. 1 user user 0 May 24 11:14 file9
My question is why does "file10" follow "file1" in this way in the terminal? When viewing files in a details or list view ordered by name or type in a GUI environment, those same files are listed as "file1", "file2", "file3", etc.
Lists of files in a GUI seem to prioritize alphabetical order by file name length, listing files from smallest length to largest. Is this correct? Is there a more technical reason for this? Is the ls
command "going out of its way" to order files the way it does, or likewise with a GUI?