|
|
Log in / Subscribe / Register

Leading spaces are common, actually

Leading spaces are common, actually

Posted Mar 26, 2009 19:21 UTC (Thu) by njs (subscriber, #40338)
In reply to: Leading spaces are common, actually by barryn
Parent article: Wheeler: Fixing Unix/Linux/POSIX Filenames

There is a use for leading spaces: They force files to appear earlier than usual in a lexicographic sort.

Are you sure? I've seen this in real-world uses too, but I thought that all the common systems were fixed to do human-style (non-ASCIIbetical) sorting a few years ago. I don't have any proprietary systems around to test, but I'll be *really* amused if the OS X Finder is missing this usability feature of GNU ls:

~/t$ touch "a" " b" "c"
~/t$ ls -l
total 0
-rw-r--r-- 1 njs njs 0 2009-03-26 12:16 a
-rw-r--r-- 1 njs njs 0 2009-03-26 12:16  b
-rw-r--r-- 1 njs njs 0 2009-03-26 12:16 c


to post comments

Leading spaces are common, actually

Posted Mar 26, 2009 21:23 UTC (Thu) by foom (subscriber, #14868) [Link] (3 responses)

Finder does not ignore spaces. I'm quite glad, because I use the space-prefix trick rather regularly. I am occasionally annoyed at how GNU ls sorts "A B" between "AA" and "AC" instead of before them: that's certainly not how my brain sorts.

Finder does however sort numbers like this, which GNU ls does not: 1 2 10

I don't really see what the point of the "human-style" sorting is if it can't even sort numbers. That seems kind of basic to me.

Leading spaces are common, actually

Posted Mar 28, 2009 1:21 UTC (Sat) by nix (subscriber, #2304) [Link] (2 responses)

Sorting numerically in GNU ls is done by 'ls -v'.

(By default, despite comments elsewhere in this thread, ls sorts
ASCIIbetically, so " 2" comes before "1".)

Leading spaces are common, actually

Posted Mar 28, 2009 1:57 UTC (Sat) by foom (subscriber, #14868) [Link] (1 responses)

> Sorting numerically in GNU ls is done by 'ls -v'.

Huh, never knew that, interesting! Never would have found that from the man page, which says "-v sort by version". That seems a remarkably poor description of what it actually does.

> (By default, despite comments elsewhere in this thread, ls sorts ASCIIbetically, so " 2" comes before "1".)

Well, not exactly: GNU ls has a default sort which depends on the locale's collation settings, and most systems default to a locale like en_US.UTF-8, so most people have it sorting in a case/accent-insensitive manner by default on their systems.

Leading spaces are common, actually

Posted Mar 28, 2009 20:36 UTC (Sat) by nix (subscriber, #2304) [Link]

It's called 'sort by version' because the function it calls (strverscmp())
was designed to sort version numbers, and because the expected use of
ls -v was sorting a directory full of version-named directories in version
order.

(And you're right on the collation sort thing: I spoke carelessly.)

Leading spaces are common, actually

Posted Mar 27, 2009 4:41 UTC (Fri) by barryn (subscriber, #5996) [Link] (2 responses)

Behavior of ls in Mac OS X 10.5.6 build 9G55:
$ pwd
/Library/Application Support/GarageBand/Instrument Library/Track Settings
$ ls -l Master | head
total 0
drwxrwxrwx   3 root  admin  102 May  3  2008  Basic
drwxrwxrwx   6 root  admin  204 May  3  2008 Ambient
drwxrwxrwx   6 root  admin  204 May  3  2008 Classical
drwxrwxrwx  11 root  admin  374 May  3  2008 Dance
drwxrwxrwx   5 root  admin  170 May  3  2008 Hip Hop
drwxrwxrwx   5 root  admin  170 May  3  2008 Jazz
drwxrwxrwx   7 root  admin  238 May  3  2008 Pop
drwxrwxrwx   7 root  admin  238 May  3  2008 Rock
drwxrwxrwx   5 root  admin  170 May  3  2008 Stadium Rock
$ 
And this matches the Finder's behavior. BTW, if the Finder behaved any other way, it would be more difficult to properly recover broken Mac OS 9.x or earlier installations using OS X -- Classic Mac OS loads files in /System Folder/Extensions in lexicographic order, and the load order matters, and the leading space trick is used very frequently there. Mac OS X 10.5 can dual-boot with Mac OS 9.x, so this still matters for some users.

Leading spaces are common, actually

Posted Mar 27, 2009 15:45 UTC (Fri) by foom (subscriber, #14868) [Link]

>Behavior of ls in Mac OS X 10.5.6 build 9G55

Well, OSX's "ls" is actually just doing a traditional strcmp sort, not anything fancy (note that it puts all uppercase characters before all lowercase).

But the Finder's sort routine is fancy. They seem to be a sort order based on Unicode TR10.

Leading spaces are common, actually

Posted Nov 15, 2009 0:32 UTC (Sun) by yuhong (guest, #57183) [Link]

"Classic Mac OS loads files in /System Folder/Extensions in lexicographic
order, and the load order matters, and the leading space trick is used very
frequently there. "
Yep, look at what they had to do about this when Apple introduced HFS+ in Mac
OS 8.1:
http://developer.apple.com/legacy/mac/library/technotes/t...
s
http://developer.apple.com/legacy/mac/library/technotes/t...


Copyright © 2026, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds