|
|
Log in / Subscribe / Register

Wheeler: Fixing Unix/Linux/POSIX Filenames

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 15:12 UTC (Wed) by rsidd (subscriber, #2582)
Parent article: Wheeler: Fixing Unix/Linux/POSIX Filenames

Yet another topic that was extensively discussed in the Unix Haters Handbook.

One gotcha that is not covered by limiting the allowed character set in filenames is this: how do you remove all your configuration files and directories (that begin with a ".")? "rm -rf .*" will have very undesirable results. And yes, I have done this to myself -- luckily the system had nightly backups.


to post comments

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 15:32 UTC (Wed) by drag (guest, #31333) [Link] (2 responses)

Uh. Wow.

Maybe if Linux folks keep identifying and fixing legacy Unix usability issues people will start referring to Linux as 'The way Unix should of been' or 'Unix done right'.

I am always really paranoid about file names in Linux when doing scripting or whatnot. It's difficult and dealing with them is always a "oh god I hope I did the escaping right" sort of deal. Because I know I can have a script that I use for lots of stuff, but sometime I may make a goober'd up filename late at night or something that can end up destroying data unless I did things exactly correct in my scripts.

Filenames with ~ in them, or < > or () or all sorts of odd things I make by mistake.

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 16:20 UTC (Wed) by epa (subscriber, #39769) [Link] (1 responses)

Maybe if Linux folks keep identifying and fixing legacy Unix usability issues people will start referring to Linux as 'The way Unix should of been' or 'Unix done right'.
I thought that was Plan 9...

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 22:14 UTC (Wed) by jordanb (guest, #45668) [Link]

While I'm not entirely sure what "Unix done right" is, but I *am* sure that a system where you get to choose between ed, sam, and acme isn't it.

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 15:42 UTC (Wed) by gnb (subscriber, #5132) [Link]

True, but that's not really a problem with the choice of names. The fact of
having named files in a directory that are actually links to the directory
and its parent necessarily gives rise to such a hazard unless you put
special-case magic in globbing to exclude them from wildcard matches, in
which case it doesn't really matter what names are picked for them as long as
they're standard. Specifying a wildcard that doesn't catch them is no harder
with the current names, the problem is remembering to do it.

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 18:43 UTC (Wed) by danielthaler (guest, #24764) [Link] (2 responses)

I just tested this, as I remeber doing this a few times without any catastrophic removals of "..". I got:

rm: cannot remove directory `.'
rm: cannot remove directory `..'

so something did prevent it from happening...

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 21:43 UTC (Wed) by mjthayer (guest, #39183) [Link] (1 responses)

I believe that GNU rm does a few additional sanity checks.

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 22:46 UTC (Wed) by nix (subscriber, #2304) [Link]

A *few*? Have a read of coreutils-7.1/src/remove.c one of these days. 50K
of mostly sanity checks and fantastically elaborate code for portably and
securely recursing down directory trees, even those longer than PATH_MAX.

GNU coreutils, like gnulib, is a goldmine of fantastic tricks (and evil
ones that it's best to, ahem, admire from a distance: e.g. the less said
about NEED_REWIND and the need for rm running everywhere to work around a
MacOS X bug, the better).

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 22:15 UTC (Wed) by csigler (subscriber, #1224) [Link]

> how do you remove all your configuration files and directories (that begin
> with a ".")? "rm -rf .*" will have very undesirable results.

IIRC, you can do something like "rm -fr .[^.]*" -- at least this WFM in the command "ls -Fa .[^.]*"

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 25, 2009 23:05 UTC (Wed) by Jonno (guest, #49613) [Link]

> How do you remove all your configuration files and directories
> (that begin with a ".")?

`rm -rf .??*` is a good start. It will miss configuration files with only
one or two characters after the dot, but I've not found any program using
such yet...

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 26, 2009 1:32 UTC (Thu) by bojan (subscriber, #14302) [Link]

Not sure if that entirely correct, but I usually use "find -mindepth 1 -name '.*'" to find such files. Doesn't seem to find "." or "..". YMMV and other warnings apply.

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 26, 2009 2:34 UTC (Thu) by k8to (guest, #15413) [Link]

You can do horrible things with GLOBIGNORE in bash.

Personally I just walk the list and filter out . and ..

Yes, it sucks.

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 26, 2009 4:58 UTC (Thu) by shimei (guest, #54776) [Link]

An interesting side effect of this proposal to make sensible file names is that a hack I use to prevent "rm -rf *" from deleting everything won't work. I keep a file named "-i" in / so if I accidentally try to rm everything, it will go into interactive mode and stop me. Of course, I think that isn't a great loss if it fixes other things.

Wheeler: Fixing Unix/Linux/POSIX Filenames

Posted Mar 27, 2009 1:28 UTC (Fri) by no_treble (guest, #49534) [Link]

rm -rf .[!.]*


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