Leading spaces are common, actually
Leading spaces are common, actually
Posted Mar 26, 2009 13:17 UTC (Thu) by barryn (subscriber, #5996)Parent article: Wheeler: Fixing Unix/Linux/POSIX Filenames
sort. (For instance, a program might create a menu at run time in lexicographic order based on
the contents of a directory, or you may want to force a file to appear near the beginning of a
listing.) This is especially common in the Mac world.
I was originally going to argue that leading spaces are necessary since people still have data
from Mac OS 9.x and earlier systems, but it turns out that this practice is far more common on
modern Mac OS X than I expected:
# find / -name ' *'
/Applications/Microsoft Office 2004/Clipart/Animations/ Animations Clip Package
/Applications/Microsoft Office 2004/Clipart/Clip Art/ Clip Art Clip Package
/Applications/Microsoft Office 2004/Clipart/Photos/ Photos Clip Package
/Applications/Microsoft Office 2004/Office/Entourage First Run/Entourage Script Menu Items/
About This Menu...
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/ Basic
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/ Basic/
Default.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/Ambient/
Ambient Basic.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/Classical/
Classical Basic.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/Dance/
Dance Basic.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/Hip Hop/
Hip Hop Basic.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/Jazz/ Jazz
Basic.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/Pop/ Pop
Basic.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/Rock/ Rock
Basic.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Master/Stadium
Rock/ Stadium Rock Basic.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Real/Band
Instruments/ No Effects.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Real/Basic Track/
No Effects.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Real/Bass/ No
Effects.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Real/Drums/ No
Effects.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Real/Effects/ No
Effects.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Real/Guitars/ No
Effects.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Real/Podcasting/
No Effects.cst
/Library/Application Support/GarageBand/Instrument Library/Track Settings/Real/Vocals/ No
Effects.cst
/Library/Scripts/Mail Scripts/Rule Actions/ Help With Rule Actions.scpt
Posted Mar 26, 2009 19:21 UTC (Thu)
by njs (subscriber, #40338)
[Link] (7 responses)
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:
Posted Mar 26, 2009 21:23 UTC (Thu)
by foom (subscriber, #14868)
[Link] (3 responses)
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.
Posted Mar 28, 2009 1:21 UTC (Sat)
by nix (subscriber, #2304)
[Link] (2 responses)
(By default, despite comments elsewhere in this thread, ls sorts
Posted Mar 28, 2009 1:57 UTC (Sat)
by foom (subscriber, #14868)
[Link] (1 responses)
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.
Posted Mar 28, 2009 20:36 UTC (Sat)
by nix (subscriber, #2304)
[Link]
(And you're right on the collation sort thing: I spoke carelessly.)
Posted Mar 27, 2009 4:41 UTC (Fri)
by barryn (subscriber, #5996)
[Link] (2 responses)
Posted Mar 27, 2009 15:45 UTC (Fri)
by foom (subscriber, #14868)
[Link]
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.
Posted Nov 15, 2009 0:32 UTC (Sun)
by yuhong (guest, #57183)
[Link]
Posted Mar 27, 2009 5:36 UTC (Fri)
by quotemstr (subscriber, #45331)
[Link] (1 responses)
The way I see it, if a program can correctly work with filenames containing spaces, it can work with a filename containing leading spaces.
It's most important to eliminate newlines and control characters in filenames. The second most important consideration is specifying UTF-8 as the preferred filename encoding. Let's not get caught up in all sorts of other wishes that will just encourage endless debate and prevent these very important changes from getting made at all.
Posted Mar 28, 2009 9:21 UTC (Sat)
by explodingferret (guest, #57530)
[Link]
perl also has problems with leading spaces in filenames, unless you use the right kind of open command (perldoc -f open).
There is a use for leading spaces: They force files to appear earlier than usual in a lexicographic sort.
Leading spaces are common, actually
~/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
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.
Leading spaces are common, actually
Leading spaces are common, actually
ASCIIbetically, so " 2" comes before "1".)
> Sorting numerically in GNU ls is done by 'ls -v'.
Leading spaces are common, actually
Leading spaces are common, actually
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.
Behavior of Leading spaces are common, actually
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.
>Behavior of ls in Mac OS X 10.5.6 build 9G55
Leading spaces are common, actually
Leading spaces are common, actually
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...
The users on a filesystem I administer use six or seven levels of leading space to sort their common jobs-in-progress directory. I've long since given up on getting them to move to a hierarchical setup.
Leading spaces are common, actually
Leading spaces are common, actually
