I understand commands such as

ls | sort -n

can do certain sorting.. but I would like Horizontal sorting just as it's being done via "ls" command.

Test in Empty folder:

 touch 1 2 12

with ls command

1  12  2

What I want to see is:

1  2  12

Horizontally just like the "ls" command.


2 Answers 2


Using the command ls -v will give you the desired output:

1 2 12

For the BSD-inclined who do not have GNU coreutils installed and therefore can't use ls -v:

 $ printf '%s\n' * | sort -n | column
 1       2       12

The printf will generate a list of names, each on its own line. The sort will sort these numerically. The column utility will arrange these into columns, much like what ls does by default.