[comp.unix.internals] I have a file named "-"

zaphod@petruz.sublink.ORG (Pietro Caselli) (02/23/91)

In an article of <26 Feb 91 05:28:22 GMT> (Benjamin H. Cowan) writes:

 >  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?

Just unlink It.

pippo()
{
int i
       if((i=unlink("-"))== -1)
                printf("Sorry ... on Minix it works !\n");
       else
                printf("Hey ma ... look it works !\n")
}
--  
.
|         Pietro Caselli        | I had a word to say, But'tis not quite the
| ...!otello!gear!petruz!zaphod | time. The best of any man's word or say,is
|   zaphod@petruz.sublink.ORG   | when its proper place arrives - And for its
|     VOICE 039-051-549423      | meaning,I keep mine till the last. (Whitman)

pfalstad@phoenix.Princeton.EDU (Paul Falstad) (02/27/91)

tchrist@convex.COM (Tom Christiansen) wrote:
>From the keyboard of gt2807a@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@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.

tif@doorstop.austin.ibm.com (Paul Chamberlain) (02/27/91)

I'm probably not the first or the last to point this out...

pfalstad@phoenix.Princeton.EDU (Paul Falstad) writes:
>If you have a file that simply has a '/' in it, you can just ...
>   rm "/"
>But a file with a - in it takes special handling.  [C programs?!]

I hope it's completely obvious that this is way out in left field.
Both of these are probably covered in the FAQ but briefly:
	a filename with "/" is difficult and has been discussed at length.
		I think it requires a "clri", editing the disk, or
		unlinking the parent directory.
	a filename with "-" can be accessed or removed by using "./-"

Paul Chamberlain | I do NOT speak for IBM.          IBM VNET: PAULCC AT AUSTIN
512/838-9662     | ...!cs.utexas.edu!ibmchs!auschs!doorstop.austin.ibm.com!tif

boyd@necisa.ho.necisa.oz.au (Boyd Roberts) (02/28/91)

In article <6661@idunno.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul Falstad) writes:
>
>If you have a file that simply has a '/' in it, you can
>just quote the slash:
>
>   rm "/"

Sorry?  What difference does the quoting make?  None.

>
>1. Write a short C program:
>
>main()
>{
>   rename("-",".nfsXXXX");
>}

Since when does _every_ system have rename(2)?

>
>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.
>

The ``let's rearrange the universe to move one rock'' approach.

>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.

Preventing all the other users from using the file-system for the
duration of this stupidity.

>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.

Of course, use the source.  We _all_ have the source.

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

Maybe even:

    rm ./-

which you can read about in the FAQ!


Boyd Roberts			boyd@necisa.ho.necisa.oz.au

``When the going gets wierd, the weird turn pro...''

subbarao@phoenix.Princeton.EDU (Kartik Subbarao) (03/01/91)

In article <2028@necisa.ho.necisa.oz.au> boyd@necisa.ho.necisa.oz.au (Boyd Roberts) writes:
>In article <6661@idunno.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul Falstad) writes:
>>
>>If you have a file that simply has a '/' in it, you can
>>just quote the slash:
>>
>>   rm "/"
>
>Sorry?  What difference does the quoting make?  None.

Pardon him - that should be a backslash:

     rm \/

There -- that should do it.

>>1. Write a short C program:
>>
>>main()
>>{
>>   rename("-",".nfsXXXX");
>>}
>
>Since when does _every_ system have rename(2)?

Okay, then use link(2) and unlink(2).

Of course, if the '-'d file was a directory, then you'd first have to
become the superuser to unlink the directory.

By the way, this article is COMPLETELY serious and is intended to be taken
as gospel truth, as was the original. We're still researching 'satire' in 
Princeton.

			
			-Kartik


--
internet# find . -name core -exec cat {} \; |& tee /dev/tty*
subbarao@phoenix.Princeton.EDU -| Internet
kartik@silvertone.Princeton.EDU (NeXT mail)  
SUBBARAO@PUCC.BITNET			          - Bitnet

chip@tct.uucp (Chip Salzenberg) (03/01/91)

"It's a group where wizards can discuss wizardly things,"
     they said.
"It's an attractive nuisance,"
     I said.

In comp.unix.wizards, gt2807a@prism.gatech.EDU (Benjamin H. Cowan) writes:
>  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?

I told you so.
-- 
Chip Salzenberg at Teltronics/TCT     <chip@tct.uucp>, <uunet!pdn!tct!chip>

ifas730@ccwf.cc.utexas.edu (03/03/91)

When the rm command parses the command line, all arguments after the
first nonoption argument are interpreted as file names.  Thus
  "rm foo -" would remove your "-" file, where foo is an nonexistent file.

John

theo@integow.uucp (Theo Hardendood) (03/05/91)

From article <128.27C67FFF@petruz.sublink.ORG>, by zaphod@petruz.sublink.ORG (Pietro Caselli):
> In an article of <26 Feb 91 05:28:22 GMT> (Benjamin H. Cowan) writes:
> 
>  >  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?
> 
> Just unlink It.
> 
Ah, read the manual of getopt. It is recommended that all programs
use these routines, and some *NIX utilities will.
Utilities using the getopt() routines have an "end of options option": --

Just try:

	rm -- -

Hope this helps

Cheers,
	Theo Hardendood
-- 
    UUCP: ..!uunet!mcsun!hp4nl!integow!theo  or  theo@integow.uucp
Theo Hardendood, Sr. software engineer, Integrity software consultants, 
         Pelmolenlaan 2, 3447 GW  Woerden, The Netherlands.
               tel +31 3480 30131, fax +31 3480 30182

jim@segue.segue.com (Jim Balter) (03/08/91)

In article <6661@idunno.Princeton.EDU> pfalstad@phoenix.Princeton.EDU (Paul Falstad) writes:
>Ask a coworker!?!  Please, please; let's at least answer the question
>before tempers get out of control.

Reading the FAQ and encouraging others to do so rather than spreading yet more 
ignorance is the best *practical* way to avoid heat and other waste products.