Super User is a question and answer site for computer enthusiasts and power users. 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

Is there an equivalent to ls -v in Mac OS X that will do version number sorting?

In Mac OS X, ls -v does NOT do version number sorting, but the Finder seems to.

share|improve this question
up vote 9 down vote accepted

The default ls in OS X does not have version sort capabilities. This is a feature of GNU ls, which comes with most Linuxes, but does not ship with OS X. You can install GNU ls through the GNU coreutils package.

The easiest way of getting it on a Mac is to install a package manager like Homebrew or MacPorts and install coreutils through it.

So, for example, install Homebrew:

/usr/bin/ruby -e "$(curl -fsSL"

Wait a bit, read the installation instructions. Then, install coreutils:

brew install coreutils

This will add all the GNU coreutils with the g prefix, so for example, you will be able to use gls instead of ls, which now offers version sort.

To override the default ls behavior (and those of other builtins), you can add this line to your ~/.bash_profile:

source /usr/local/Cellar/coreutils/8.12/aliases

Note that this might affect other programs that rely upon the BSD version. If you just want to alias ls, use the following instead:

alias ls="$brew_prefix/bin/gls"
share|improve this answer

bash script for sorting version numbers correctly on mac terminal

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .