ugh.book

(singke) #1

28 Welcome, New User!


Then there’s the story of the poor student who happened to have a
file called “-r” in his home directory. As he wanted to remove all his
non directory files (I presume) he typed:

% rm *

... And yes, it does remove everything except the beloved “-r” file...
Luckily our backup system was fairly good.

Some Unix victims turn this filename-as-switch bug into a “feature” by
keeping a file named “-i” in their directories. Type “rm *” and the shell
will expand this to “rm -ifilenamelist” which will, presumably, ask for
confirmation before deleting each file. Not a bad solution, that, as long as
you don’t mind putting a file named “-i” in every directory. Perhaps we
should modify the mkdir command so that the “-i” file gets created auto-
matically. Then we could modify the ls command not to show it.

Impossible Filenames

We’ve known several people who have made a typo while renaming a file
that resulted in a filename that began with a dash:
% mv file1 -file2

Now just try to name it back:
% mv -file2 file1
usage: mv [-if] f1 f2 or mv [-if] f1 ... fn d1
(‘fn’ is a file or directory)
%

The filename does not cause a problem with other Unix commands because
there’s little consistency among Unix commands. For example, the file-
name “-file2” is kosher to Unix’s “standard text editor,” ed. This example
works just fine:
% ed -file2
4347

But even if you save the file under a different name, or decide to give up on
the file entirely and want nothing more than to delete it, your quandary
remains:

(^7) The “434” on the line after the word “ed” means that the file contains 434 bytes.
The ed editor does not have a prompt.

Free download pdf