How to make ls sort by file extension and then name?

I think the complete answer is more of a combination of the above.

-X (later --sort=extension) has been supported in Linux since at least FC3 and will sort based on extension. --group-directories-first was added more recently (maybe around FC8?). However, combining the two doesn't seem to work (at least on FC8).

The primary issue seems to be with the use of singular primary sort keys. See this mailing list discussion for some insight into it.


On Linux,

$ ls --group-directories-first

-X is the option you're looking for:

ls -lX

Tags:

Linux

Shell