[comp.sys.att] Problem removing a file

dave@arnold.UUCP (Dave Arnold) (01/30/89)

erict@flatline.UUCP (The Evil Mel Fujitsu) writes:
> 
> I've created, in my home directory, a file by the name of:
> -ef
mv \-ef Xef
rm Xef
-- 
Dave Arnold
...!uunet!ccicpg!arnold!dave
Volt Delta Resources     Phone: (714) 921-7635

scott@keysec.UUCP (Scott Bartram) (01/30/89)

 Having run up against this problem on various occasions, I can offer several
solutions:

First, find the real name of the file:
  
  1. use "ls -b" to display non-printing chars in octal, or if this fails
  2. type "od -c . | more". This will display the current directory (including
     removed files). It will look something like this:

0000000 004 271   .  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000020 001 023   .   .  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0  \0
0000040 004 302   .   p   r   o   f   i   l   e  \0  \0  \0  \0  \0  \0
0000060 003   ;   .   o   l   d   n   e   w   s   r   c  \0  \0  \0  \0
0000100 000 000   .   r   n   h   e   a   d  \0  \0  \0  \0  \0  \0  \0

  Lines with "000 000" are deleted files.

  So now you should know the actual file name.

Second, remove the file:

  1. try using "echo":

    rm `echo "foo\007bar"`

  2. write a simple C program:

    main()
    {
      unlink("foo\377bar");
    }

-scott
-- 
=============================================================
Scott Bartram                         Key Systems Engineering
VOICE: +1 301 731 7310                4404 Cavalcade Ct.
EMAIL: uunet!keysec!scott             Burtonsville, MD 20866

jbm@uncle.UUCP (John B. Milton) (01/30/89)

In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
[ made a filed name -ef, can't remove it]

rm, like most utilities uses getopt(3) to get the switches from the command
line. A quick look at the man page will give youyour answer. If you put an
option "--" on the command line, getopt will stop looking at switches.
What you want is:
rm -- -ef

Ouch, too simple. The -- feature is very valuable with grep:

grep -- -rf script

John

-- 
John Bly Milton IV, jbm@uncle.UUCP, n8emr!uncle!jbm@osu-cis.cis.ohio-state.edu
(614) h:294-4823, w:764-2933;  Got any good 74LS503 circuits?

pfales@ttrde.UUCP (Peter Fales) (01/30/89)

In article <695@flatline.UUCP>, erict@flatline.UUCP (The Evil Mel Fujitsu) writes:
> Ok, I've really done it now.  I've created, in my home directory,
> a file by the name of:
> -ef

It was almost a religious experience when I found a general solution to
this kind of problem:

1) ls -i  (to get the inode number of  the file.  Call it N)
2) find . -inum N -print -exec rm {} \;

It works on every problem I have had:  names with spaces, names with
my KILL or INTR characters, names starting with '-', etc.  

Disclaimer:  Your mileage may vary.

-- 
Peter Fales			AT&T, Room 2F-217
				200 Park Plaza
UUCP:	...att!ttrde!pfales	Naperville, IL 60566
Domain: pfales@ttrde.att.com	work:	(312) 416-5357		

lenny@icus.islp.ny.us (Lenny Tropiano) (01/30/89)

In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
|>
|>Ok, I've really done it now.  I've created, in my home directory,
|>a file by the name of:
|>-ef
|>
|>None of the following rm options work: *f, *ef, -*f, -i *
|>
|>The error returned?
|>
|>rm: illegal option -- e
|>usage: rm [-fir] file ...
|>
|>Any hints/suggestions?

Yeah, I do ... :-)

Rename the file with "mv(1)", since that doesn't have any argument switches,
it won't complain about the "-ef", then remove it.

$ mv -ef junk
$ rm junk

-Lenny
-- 
Lenny Tropiano             ICUS Software Systems         [w] +1 (516) 582-5525
lenny@icus.islp.ny.us      Telex; 154232428 ICUS         [h] +1 (516) 968-8576
{talcott,decuac,boulder,hombre,pacbell,sbcs}!icus!lenny  attmail!icus!lenny
        ICUS Software Systems -- PO Box 1; Islip Terrace, NY  11752

mvadh@cbnews.ATT.COM (andrew.d.hay) (01/30/89)

In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
"Ok, I've really done it now.  I've created, in my home directory,
"a file by the name of:
"-ef

try moving it to an innocuous name, like fubar (;^>)

-- 
Andrew Hay		+------------------------------------------------------+
Apprentice Polymath	| Yes, the wages of sin ARE death, but after they take |
AT&T-BL Ward Hill MA	| taxes out, it's kind of a tired feeling really       |
mvuxq.att.com!adh	+------------------------------------------------------+

john@polyof.UUCP ( John Buck ) (01/30/89)

In article <589@icus.islp.ny.us>, lenny@icus.islp.ny.us (Lenny Tropiano) writes:
> In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
> |>a file by the name of:
> |>-ef
> |>None of the following rm options work: *f, *ef, -*f, -i *
> |>Any hints/suggestions?
> $ mv -ef junk
> $ rm junk

Fastest way:
$ rm x -ef
rm: x nonexistant   (or some such)
$ ... but -ef is removed...

john@polyof.poly.edu

norm@oglvee.UUCP (Norman Joseph) (01/30/89)

From article <695@flatline.UUCP>, by erict@flatline.UUCP (The Evil Mel Fujitsu):
> 
> Ok, I've really done it now.  I've created, in my home directory,
> a file by the name of:
> -ef
> 
> None of the following rm options work: *f, *ef, -*f, -i *
> 
> Any hints/suggestions?

Two hints:

	1)	ls -i
	2)	find . -inum <n> -exec rm -i {} \;

(Caveat:  I don't own or use a unix-pc, so I'm only guessing that these
commands with these options are available to you)
-- 
Norm Joseph - Oglevee Computer System, Inc.
UUCP: ...!{pitt,cgh}!amanue!oglvee!norm
"Mate, that parrot wouldn't *VROOM* if you put four million volts through it!"

bamford@ihlpf.ATT.COM (Harold E. Bamford) (01/31/89)

In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
>Ok, I've really done it now.  I've created, in my home directory,
>a file by the name of:
>-ef
>None of the following rm options work: *f, *ef, -*f, -i *

Try:
	mv -ef x
	rm x

Welcome to the club...

jeffj@pedsga.UUCP (01/31/89)

In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
|>Ok, I've really done it now.  I've created, in my home directory,
|>a file by the name of:
|>-ef
|>rm: illegal option -- e
|>usage: rm [-fir] file ...

The recent versions of rm (and all programs that take options)
use getopt(3) to parse the argument line.
Both the SVID and the programmer's manual mention that `--' is used
to terminate options to allow arguments beginning with `-', so
	rm -- -ef
should work.  If my suggestion was taken, the SVR4.0 manual should
have this as an example in the rm(1) man page.

res@cbnews.ATT.COM (Robert E. Stampfli) (01/31/89)

In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
>Ok, I've really done it now.  I've created, in my home directory,
>a file by the name of:
>-ef
>None of the following rm options work: *f, *ef, -*f, -i *

How about:

	rm ./-ef

Rob Stampfli
att!cbnews!res (work)
osu-cis!n8emr!kd8wk!res (home)

ekrell@hector.UUCP (Eduardo Krell) (01/31/89)

Files with names starting with "-" can be removed by "rm ./-whatever"
(like "rm ./-ef").
    
Eduardo Krell                   AT&T Bell Laboratories, Murray Hill, NJ

UUCP: {att,decvax,ucbvax}!ulysses!ekrell  Internet: ekrell@ulysses.att.com

mark@mkvpc.UUCP (mark varnell) (01/31/89)

In article <695@flatline.UUCP>, erict@flatline.UUCP (The Evil Mel Fujitsu) writes:
> 
> Ok, I've really done it now.  I've created, in my home directory,
> a file by the name of:
> -ef
> None of the following rm options work: *f, *ef, -*f, -i *
> The error returned?
> rm: illegal option -- e


I've done this one before myself..
Try making a dummy file 'fdummy' and
then:
rm fdummy -ef

Thus rm will not try to interpret -ef as an option.


-- 
           +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
            Mark Varnell mark@mkvpc.UUCP
            {mtune!gladys, kd4nc!gladys, bakerst}!rbdc!mkvpc!mark
           +++++++++++++++++++++++++++++++++++++++++++++++++++++++++

sac@conrad.UUCP (Steven A. Conrad) (02/01/89)

In article <102@keysec.UUCP> scott@keysec.UUCP (Scott Bartram) writes:
>
>Second, remove the file:
>
>  1. try using "echo":
>
>    rm `echo "foo\007bar"`

Frequently the easiest way is to use the wild character symbol '?'
in place of any nonprinting characters or characters which would
otherwise prevent the command from being carried out.
-- 
Steven A. Conrad,  Department of Medicine (Critical Care)
Louisiana State University Medical Center, Shreveport, LA
UUCP: sac@conrad.UUCP,   Internet: conrad@manta.pha.pa.us
"Silence  is the only  successful  substitute for brains"

tbm@cbnews.ATT.COM (thomas.b.merrick) (02/02/89)

In article <791@pedsga.UUCP> jeffj@pedsga.UUCP (Jeff Jonas,TF,7) writes:
>In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
>|>Ok, I've really done it now.  I've created, in my home directory,
>|>a file by the name of:
>|>-ef
>|>rm: illegal option -- e
>|>usage: rm [-fir] file ...
>

Well, the easiest trick is like ::

      rm ./-ef

Works every time, even if rm does not understand "--".

Tom Merrick ATT BTL  Ward Hill MA    att!mvuxd!tbm

jon@jonlab.UUCP (Jon H. LaBadie) (02/02/89)

In article <350@arnold.UUCP>, dave@arnold.UUCP (Dave Arnold) writes:
> erict@flatline.UUCP (The Evil Mel Fujitsu) writes:
> > 
> > I've created, in my home directory, a file by the name of:
> > -ef
> mv \-ef Xef
> rm Xef

A simple way to "trick" rm into removing "dash" files
is to not place the dash file name first.  Give a
false, dummy name, then the dash file name.

	rm xyzzy -ef

Rm will complain about xyzzy not being there, but will
accecpt -ef as a file name, not an option (options
comming before file names).
-- 
Jon LaBadie
{att, ulysses, princeton, bcr}!jonlab!jon

ebh@argon.UUCP (Ed Horch) (02/04/89)

In article <154@conrad.UUCP> sac@conrad.UUCP (Steven A. Conrad) writes:
>Frequently the easiest way is to use the wild character symbol '?'
>in place of any nonprinting characters or characters which would
>otherwise prevent the command from being carried out.

That won't work if you're trying to remove a file named "-ef", for the
same reason that using * doesn't work.  It's the shell that does the
expansion of wild cards, not the rm command itself.  So, if you
specify the file "-ef" as "?ef", the rm command is invoked by the
shell as "rm -ef" after all.  You have to use one of the other tricks
that have been posted here, and also posted in the "Frequently Asked
Questions" article in news.announce.newusers.  To summarize:

	rm ./-ef
	rm -- -ef
	mv -ef foo; rm foo
	cd ..; rm -r directory
	etc.

-Ed

dpw@lemuria.usi.com (Darryl P. Wagoner) (02/04/89)

In article <589@icus.islp.ny.us> lenny@icus.islp.ny.us (Lenny Tropiano) writes:
}In article <695@flatline.UUCP> erict@flatline.UUCP (j eric townsend) writes:
}|>
}|>Ok, I've really done it now.  I've created, in my home directory,
}|>a file by the name of:
}|>-ef
}|>
}|>Any hints/suggestions?
}
}Yeah, I do ... :-)
}
}Rename the file with "mv(1)", since that doesn't have any argument switches,
}it won't complain about the "-ef", then remove it.
}
}$ mv -ef junk
}$ rm junk
}
}-Lenny


Also you can do a rm ./-ef.  That will kept the - from being picked up 
as an option.-- 
Darryl Wagoner		(home) dpw@lemuria.uucp or wagoner@imokay.dec.com
Digital Equipment Corp; 	OS/2, Just say No!
Boxboro, Ma  			(w) 508-264-5586
UUCP:  virgin!lemuria!dpw

eric@becker.UUCP (Eric Siegerman) (02/13/89)

In article <836@ttrde.UUCP> pfales@ttrde.UUCP (Peter Fales) writes:
> In article <695@flatline.UUCP>, erict@flatline.UUCP (The Evil Mel Fujitsu) writes:
> > Ok, I've really done it now.  I've created, in my home directory,
> > a file by the name of:
> > -ef
> [...]
> 1) ls -i  (to get the inode number of  the file.  Call it N)
> 2) find . -inum N -print -exec rm {} \;
>
> It works on every problem I have had:
> [...]
> Disclaimer:  Your mileage may vary.

Your mileage might in fact be *greater* than expected:  if you
originally messed yourself up by

    ln good_file garbage_name

the recommended approach will happily remove both links to your
file!  The simplest approach to erict's specific problem (while
admittedly not a general solution) is

    rm ./-ef
-- 
Eric Siegerman, Toronto, Ont.
eks@kneller.UUCP,  eric@becker.UUCP,  ...!utzoo!mnetor!becker!kneller!eks