Why ls Lists clip_10 Before clip_1: Locale Changes File Order
Listing twelve numbered clips in one folder produced three different orders depending on the tool and locale used. Under the C locale, ls compares names as plain bytes, so clip_10 falls between clip_1 and clip_2. Under en_US.UTF-8, punctuation is ignored and digits sort ahead of letters, which places clip_10 first. Python's os.listdir and glob.glob returned files in neither order, and sorted() matched the C locale. Using ls -v, sort -V, or zero-padded names made every tool produce the intended 1-to-12 sequence.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.


Discussion (0)
Log in to join the discussion and vote.
Log in