When listing directories in Bash, I would like the value of numbers to be taken into account.

Currently this is the output I get:

$ ls 
test_1.txt  
test_11.txt 
test_12.txt 
test_2.txt  
test_3.txt

As you can see, ls does not take the value of 11 and 12 into acount and lists it before 2, even though they are bigger numbers. Is there some way to get the output to be this instead:

$ ls 
test_1.txt  
test_2.txt  
test_3.txt
test_11.txt 
test_12.txt

I've checked the man page and found nothing. Any ideas?

link|improve this question
feedback

1 Answer

up vote 2 down vote accepted

In GNU coreutils ls, the ls -v (version sort) option should do it.

Otherwise you have to pipe the output through sort -n or sort -V.

link|improve this answer
Thanks for pointing me in the right direction. It seems that ls -v is only un the GNU coreutils, since man pages for the BSDs give nothing like it. I'm on OSX. – termCap May 22 '11 at 16:33
@termCap You can install coreutils later using Homebrew – slhck May 22 '11 at 16:36
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.