tags:

views:

2600

answers:

5

Can you sort ls listing by name? Amazingly enough (Or I must be brain-dead) I dont see anything in man pages or can find anything on google :)

+6  A: 

My ls sorts by name by default. What are you seeing?

Evert
My Bad ... I was brain-dead indeed! ... Thanks Nobert Hartl, tvanfosson and Evert :)
Devang Kamdar
+1  A: 

From the man page (for bash ls):

Sort entries alphabetically if none of -cftuSUX nor --sort.

jwoolard
There is no "bash ls". Do "which ls"
Norbert Hartl
@Norbert: You are correct, but `which ls` would succeed even if bash had a builtin ls. Rather, do `builtin ls` in bash, and get an error.
Pianosaurus
@Norbert: `which` always returns a path. Use `type ls` to determine what the shell thinks `ls` is (built-in, function, executable).
ephemient
+4  A: 

For something simple, you can combine ls with sort. For just a list of file names:
ls -1 | sort

To sort them in reverse order:
ls -1 | sort -r

Mark
A: 

NOTICE: "a" comes AFTER "Z":

$ touch A.txt aa.txt Z.txt

$ ls

A.txt Z.txt aa.txt

russian_spy
A: 

check your .bashrc file for aliases

Sujit