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.


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 https://raw.github.com/gist/323731)"

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"


bash script for sorting version numbers correctly on mac terminal

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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