Skip to main content
`(on)` is sort by name which is the default, `n` for that sort by name to be numerical. missing -d
Source Link
Stéphane Chazelas
  • 584.8k
  • 96
  • 1.1k
  • 1.7k

With GNU ls (i.e. on Linux, Cygwin, or other systems that have GNU ls specifically installed):

ls -v

In zsh:

echo *(onn)

In other shells:

echo log?.gz log??.gz log???.gz

Replace echo by printf '%s\n' if you want each file name on a separate line.

If you want file metadata as well (ls -l) and you don't have GNU ls, you'll need to call ls separately for each file name or group of file names that you want to see in lexicographic order.

ls -lld log?.gz; ls -lld log??.gz; ls -lld log???.gz

To avoid these difficulties, use enough leading zeroes in your file names so that the lexicographic sort is human-friendly (log001.gz, etc).

With GNU ls (i.e. on Linux, Cygwin, or other systems that have GNU ls specifically installed):

ls -v

In zsh:

echo *(on)

In other shells:

echo log?.gz log??.gz log???.gz

Replace echo by printf '%s\n' if you want each file name on a separate line.

If you want file metadata as well (ls -l) and you don't have GNU ls, you'll need to call ls separately for each file name or group of file names that you want to see in lexicographic order.

ls -l log?.gz; ls -l log??.gz; ls -l log???.gz

To avoid these difficulties, use enough leading zeroes in your file names so that the lexicographic sort is human-friendly (log001.gz, etc).

With GNU ls (i.e. on Linux, Cygwin, or other systems that have GNU ls specifically installed):

ls -v

In zsh:

echo *(n)

In other shells:

echo log?.gz log??.gz log???.gz

Replace echo by printf '%s\n' if you want each file name on a separate line.

If you want file metadata as well (ls -l) and you don't have GNU ls, you'll need to call ls separately for each file name or group of file names that you want to see in lexicographic order.

ls -ld log?.gz; ls -ld log??.gz; ls -ld log???.gz

To avoid these difficulties, use enough leading zeroes in your file names so that the lexicographic sort is human-friendly (log001.gz, etc).

Source Link
Gilles 'SO- stop being evil'
  • 865.3k
  • 205
  • 1.8k
  • 2.3k

With GNU ls (i.e. on Linux, Cygwin, or other systems that have GNU ls specifically installed):

ls -v

In zsh:

echo *(on)

In other shells:

echo log?.gz log??.gz log???.gz

Replace echo by printf '%s\n' if you want each file name on a separate line.

If you want file metadata as well (ls -l) and you don't have GNU ls, you'll need to call ls separately for each file name or group of file names that you want to see in lexicographic order.

ls -l log?.gz; ls -l log??.gz; ls -l log???.gz

To avoid these difficulties, use enough leading zeroes in your file names so that the lexicographic sort is human-friendly (log001.gz, etc).