Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

2 Answers 2

up vote 6 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 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"
share|improve this answer

http://www.islamadel.com/en/notes/6-computer/37-sort-version-number-mac

bash script for sorting version numbers correctly on mac terminal

share|improve this answer

Your Answer

 
discard

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.