All Topics
All Topics
Technology
Technology
Design
Design
Programming
Programming
Science
Science
News
News
Gaming
Gaming
Entertainment
Entertainment
Business
Business
Finance
Finance
Sports
Sports
Health
Health
Food
Food
Travel
Travel
Art
Art
Music
Music
Books
Books
Education
Education
Politics
Politics
Personal
Personal
No algorithm. No AI slop. No ads. Just RSS. Pro-human. Indie writers. Real journalism. Open web. Chronological. Hand toasted.

Understanding macOS vs Linux Sort Command Differences in Collation Behavior

By

g0xA52A2A

7mo ago· 5 min readenInsight

Summary

The article documents a technical investigation into why the sort command produces different results on macOS versus Linux systems, even when using the same locale settings. The author discovers that macOS uses a different collation algorithm (LC_COLLATE) that treats hyphens differently than Linux systems, causing package names like 'python-dev' and 'python3-dev' to be sorted in reverse order. The article provides detailed technical analysis, code examples, and comparisons between the two operating systems' sorting behaviors.

Key quotes

· 5 pulled
Same locale, different order (or technically, collation)
This is not even a difference between GNU and BSD userland; coreutils sort on macOS produces the same output as /usr/bin/sort
The difference is in the collation algorithm, not the locale data
macOS treats hyphen as a primary difference, while Linux treats it as a tertiary difference
This can cause real problems when dealing with sorted lists that need to be consistent across platforms
Snippet from the RSS feed
Today I noticed something interesting while working with a sorted list of package names: sort(1) orders them differently on macOS and Linux (Ubuntu 20.04). A very simple example, with locale set explicitly:

You might also wanna read