I have a file named "-"

Paul Falstad pfalstad at phoenix.Princeton.EDU
Wed Feb 27 15:39:56 AEST 1991


tchrist at convex.COM (Tom Christiansen) wrote:
>From the keyboard of gt2807a at prism.gatech.EDU (Benjamin H. Cowan):
>:  I have a file whose name consists of the single character "-".  I can't
>:rm it or mv it or cat it or more it or anything to it.  How can I get rid of
>:it?

>Ask a coworker.
>
>Burn your computer.
>
>Throw out the disk.

Ask a coworker!?!  Please, please; let's at least answer the question
before tempers get out of control.

If you have a file that simply has a '/' in it, you can
just quote the slash:

   rm "/"

But a file with a - in it takes special handling.  Fortunately there are
many ways to remove a file like this.

1. Write a short C program:

main()
{
   rename("-",".nfsXXXX");
}

Simply run this, and the - file will be renamed to a .nfsXXXX, which
will probably be deleted by cron within a day.  Slick huh?

2. (Even cooler)

main()
{
struct timeval xx = { 0,0 };

   rename("-","#foo#");
   utimes("#foo#",&xx);
}

This will rename - to a file beginning with #, and date it Dec 31, 1969.
The file will, again, probably be deleted by cron.

3. Tar up the whole directory and then remove it with rm -rf, then use a
binary editor to change the name of the file to something else.  Then
untar it and delete it normally.

4. Use ls -i to get the inode of the file, and then ask the super-user
to run clri on the inode, followed by fsck.

5. Get the source to rm, and remove all the option handling routines
with #ifdefs.  Then compile it and use the simpler version of rm to
delete the file.

There may be simpler ways but these should work although I haven't
tested any of them.  Hope this helps.  ;-)

--
  Paul Falstad, pfalstad at phoenix.princeton.edu PLink:HYPNOS GEnie:P.FALSTAD
  I think there should be more race prejudice.  <slap> LESS race prejudice.
     Princeton University apologizes for the content of this article.



More information about the Comp.unix.internals mailing list