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

Consider the following input to sort:

cat > foo <<EOM

Now try running sort foo

The output is not sorted when trying this on any of my linux boxes (gnu coreutils versions 6.9-7.4). The output is sorted when run under cygwin (gnu coretuils 8.5). Comments?

share|improve this question
up vote 13 down vote accepted

Sorting depends on the locale; specifically, it depends on $LC_COLLATE (possibly overridden by $LC_ALL), falling back to $LANG if it doesn't exist. The command locale will show you what values you're effectively working with. See man 3 strcoll, man 3 setlocale, etc.

LC_COLLATE=C (or POSIX or no locale at all) results in a strict byte-by-byte comparison.

LC_COLLATE=en_US.utf8 results in an alphabetical-equivalence sort, with punctuation ignored and characters within the same equivalence class treated equally.

share|improve this answer
Indeed, export LC_COLLATE=C makes sort behave as expected – Leo Alekseyev Nov 30 '10 at 0:47
Accents are not completely ignored. Stephane sorts before Stéphane, but Stephanie sorts after Stéphane. é is equivalent to e (like ê, ë, ...), but if there's a tie, then the order between those is well defined. It's the same in a good old paper dictionary. – Stéphane Chazelas May 16 '14 at 14:43
If you really want to know it all: unicode.org/reports/tr10 – Carpetsmoker Nov 24 '14 at 20:05

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.