Skip to main content
4 of 6
deleted 62 characters in body
Mikel
  • 58.7k
  • 16
  • 136
  • 155

If you can't get ls to sort the way you want, try shell expansion.

You can use file name patterns to run ls with a list of files that the shell already sorted, bypassing the method that ls uses.

ls -lf _* [!_]* 

Assuming you have the files

_a a _b b _c c 

this is like running

ls -lf _a _b _c a b c 

Explanation:

_* is a shell pattern matching any file name beginning with an underscore, expanded in alphabetic order.

[!_]* matches any file name not beginning with an underscore, expanded in alphabetic order.

-f tells ls to not sort, because the shell already did.

More information: bash filename expansion

Mikel
  • 58.7k
  • 16
  • 136
  • 155