Simple listing directory question

I have a very basic question:
How do I list all the directories in the following order?
If I do

 ls -l 

I get different results than I want to achieve.

dir.1
dir.2
dir.3
dir.4
dir.5
dir.6
dir.7
dir.8
dir.9
dir.10
dir.11
dir.12
dir.13
dir.14
dir.15
dir.16
dir.17
dir.18
dir.19
dir.20
dir.21
dir.22
dir.23
dir.24
dir.25
dir.26
dir.27
dir.28
dir.29
dir.30
dir.31

ls | sort

try using the above command....

By default, ls sorts the listing in lexicographical order. To change that (for this particular case), use

ls dir*|sort -t. -k2n

If you have a free hand in designing the naming convention, you could also fix the length of the numeric suffix, say to 5 digits with leading zeros, so:-

$ ls -1
dir.00001
dir.00002
dir.00003
dir.00004
dir.00005
dir.00006
dir.00007
dir.00008
dir.00009
dir.00010
dir.00011
dir.00012

It depends what you can define and what you are forced to use.

I hope that this helps.

Robin
Liverpool/Blackburn

That will attempt to sort the contents of multiple directories. You can use -d, but if there are very many directories, there could be a problem executing the command after the shell pathname expansion has generated a long list. grep would be a better solution.

Regards,
Alister