Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a directory with files named "1", "2",...,"9", "10", "11", ..., "20", "21", ... inside.

Can I list them in the order of "1", "2",...,"9", "10", "11", ..., "20", "21", ...?

I have tried ls -ls. It doesn't list the files that way, but instead "1", "10", "11", ..., "19", "2", "20", "21", .... I guess a feature like that will be helpful sometimes.

share|improve this question
up vote 5 down vote accepted

With GNU ls (as found on most Linux distributions), you can use ls -v, where -v, from the man page

 -v     natural sort of (version) numbers within text
share|improve this answer

GNU ls -v has already been mentioned, but for other commands, if your shell is zsh, you can affect the order wildcards are expanded with globbing qualifiers.

For instance:

printf '%s\n' *(om)

Would list the files sorted by modification time (from the newest to the oldest), *(Om) to reverse the sort order (from the oldest to the newest).

*(n) would sort the files numerically. So if your ls is not the GNU ls, you could still do:

ls -fdl -- *(n)

To get the list numerically sorted.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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