[comp.sys.hp] Trying to remove a file called "-ls"

diblanch@sdrc.UUCP (Jeff Blanchet) (03/11/89)

I seem to have stumbled across a bug that occurs on the HP. I created a file
called "-ls". Now on any other UNIX system all I have to do is issue the
command "rm -i *". This doesn't work on the HP 9000/300 series running
HP U/X 6.0 and 6.2. I tried all kinds of different ways to get rid of
the file. I tried using the "mv" command but that didn't work on the 300.
I tried the mv command on the 800 and I could use the "mv" command and
then remove the file.

Anyway I have found one way to get rid of a file with this type of name.
"find . -name "-ls" -exec rm {} \;" got rid of the file.

Pretty interesting!!! Anyone else know of a way to delete such a file?



P.S. I have tried using "rm -i *" on other UNIX systems and it works fine.


Jeff Blanchet               UUCP: uunet!sdrc!diblanch
SDRC
Cincinnati Ohio

milburn@me1.lbl.gov (John Milburn) (03/11/89)

In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>I seem to have stumbled across a bug that occurs on the HP. I created a file
>called "-ls". Now on any other UNIX system all I have to do is issue the

Try rm "-ls".


-jem

milburn@me1.lbl.gov (John Milburn) (03/11/89)

In article <2087@helios.ee.lbl.gov> JEMilburn@lbl.gov writes:
>In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>
>Try rm "-ls".

Oops! I had better learn to try things before advising. This command
doesn't work.

-jem

leres@ace.ee.lbl.gov (Craig Leres) (03/11/89)

John Milburn writes:
>In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>>I seem to have stumbled across a bug that occurs on the HP. I created a file
>>called "-ls". Now on any other UNIX system all I have to do is issue the
>
>Try rm "-ls".

This may work under hpux, but it doesn't under Berkeley Unix. My
favorate way to remove a file with a leading dash is:

	% rm foo -ls

It doesn't matter if foo exists or not; once it sees an argument that
doesn't have a leading dash, it stops looking.

		Craig

nick@hp-sdd.hp.com (Nick Flor) (03/12/89)

In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>
>Anyway I have found one way to get rid of a file with this type of name.
>"find . -name "-ls" -exec rm {} \;" got rid of the file.
>
>Pretty interesting!!! Anyone else know of a way to delete such a file?
>

Yes.  The  problem, of course, is that the shell is trying to  interpret
the file name as command line options.  So, just do something to make it
realize that it's actually the file name.

Try 'rm  ../(current  directory  name)/-ls'.  You don't need the  single
quotes.  If it's on your top level  directory  you can type "rm  ~/-ls".
Or just type in the full path name.

Nick
-- 
+ Disclaimer: The above opinions are my own, not necessarily my employer's.   +
+ Oh, sure. Sure. I'm going. But I got  | Nick V. Flor           * * o * *    +
+ your number, see? And one of these    | Hewlett Packard SDD   * * /I\ * *   +
+ days, the joke's gonna be on you.     | ..hplabs!hp-sdd!nick  * * / \ * *   +

allyn@hp-sdd.hp.com (Allyn Fratkin) (03/12/89)

In article <1818@hp-sdd.hp.com>, nick@hp-sdd.hp.com.UUCP (Nick Flor) writes:
> Try 'rm  ../(current  directory  name)/-ls'.  You don't need the  single
> quotes.  If it's on your top level  directory  you can type "rm  ~/-ls".

rm ./-ls

is an easier and equally effective method.  incidentally, the original poster
claimed that "rm -i *" worked on machines other than his hp.  well, i tried 
"rm -i *" on a 4.3 BSD VAX, and it did not work.  i think the only way it 
could have worked is if the original poster had a file that sorted 
before -ls in his directory.
-- 
 From the virtual mind of Allyn Fratkin            allyn@sdd.hp.com
                          San Diego Division       - or -
                          Hewlett-Packard Company  uunet!ucsd!hp-sdd!allyn

frank@zen.co.uk (Frank Wales) (03/13/89)

In article <2089@helios.ee.lbl.gov> leres@helios.ee.lbl.gov
 (Craig Leres) writes:
>John Milburn writes:
>>In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>>>I seem to have stumbled across a bug that occurs on the HP. I created a file
>>>called "-ls". Now on any other UNIX system all I have to do is issue the
>>>command "rm -i *".

I'd be surprised if this only complained on HP-UX.  The behaviour you
describe is what I'd expect on a Sys V machine which tries to be consistent
about option parsing, simply treating the file name as if it were another
set of command line switches.  It is not a bug.

>>Try rm "-ls".

This definitely won't make any difference -- quoting is a shell mechanism
for assembling arguments, and isn't perceived by the invoked commands.

>This may work under hpux, but it doesn't under Berkeley Unix. My
>favorate way to remove a file with a leading dash is:
>
>	% rm foo -ls
>
>It doesn't matter if foo exists or not; once it sees an argument that
>doesn't have a leading dash, it stops looking.

But its exit status might be a problem if this is in a shell script, say.

Now for the answer: to terminate option parsing on rm (and most other
commands which accept command line switches), put a '--' in the command
line.  Beyond that, anything starting with a '-' won't be picked up
as an option.  So, to remove the offending file, use "rm -- -ls".
This works on both 300 and 800 series HP-UX (and probably also 500).

It is down to the individual command to recognise the '--' convention,
though; your mileage may vary.
--
Frank Wales, Systems Manager,        [frank@zen.co.uk<->mcvax!zen.co.uk!frank]
Zengrange Ltd., Greenfield Rd., Leeds, ENGLAND, LS9 8DB. (+44) 532 489048 x217 

frank@hpuxa.ircc.ohio-state.edu (Frank G. Fiamingo) (03/13/89)

To delete a file with a "-" as the first character you need to
clearly separate that file from the command options.  You can do
this by including another file with a "normal" name first, e.g.
rm dummyfile -ls
rm will then remove file "-ls" without problem.

Frank Fiamingo
frank@hpuxa.ircc.ohio-state.edu

diblanch@sdrc.UUCP (Jeff Blanchet) (03/13/89)

In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>I seem to have stumbled across a bug that occurs on the HP. I created a file
>called "-ls". Now on any other UNIX system all I have to do is issue the


Thanks to the replys. Of course as usual in most cases a simple solution
is the answer to my problem. In my original posting I stated that I could 
remove a file called "-ls" using "rm -i *". This works on some types of wierd
filnames but not "-ls". This occurs on all UNIX systems that I have tried it
on. I realize how it happens. Below are a few ways that I have received that
will delete the file:

    $ rm ./-ls

Probably the most obvious that I overlooked.

    $ rm -- -ls

Since the dash appears first in a seperate argument the - in the "-ls"
part is used as a filename.

    $ rm foo -ls

Adding a file that doesn't exist to be first in the list also deletes the
"-ls" file. The remove command will say the foo wasn't found but the "-ls"
file does get deleted.

Thanks to all who looked into this problem and found the above solutions.

Jeff Blanchet                UUCP:  uunet!sdrc!diblanch
SDRC
Cincinnati Ohio

pdg@hpcupt1.HP.COM (Paul Gootherts) (03/14/89)

>	Try 'rm ../(current directory name)/-ls'.  You don't need the
>	single quotes.  If it's on your top level directory you can type
>	"rm ~/-ls".  Or just type in the full path name.

"rm ./-ls" works too, and is a little simpler.

Paul Gootherts, Hewlett-Packard Co, hplabs!hpda!pdg

raveling@vaxb.isi.edu (Paul Raveling) (03/14/89)

In article <2087@helios.ee.lbl.gov> JEMilburn@lbl.gov writes:
>In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>>I seem to have stumbled across a bug that occurs on the HP. I created a file
>>called "-ls". Now on any other UNIX system all I have to do is issue the
>
>Try rm "-ls".

	That produces:

	rm: illegal option -- l
	rm: illegal option -- s
	usage: rm [-fir] file ...


	However, it DOES work to say "rm ./-ls".  In this case you
	can fool ls by sticking in an otherwise superflous path.

	Now suppose you want to search for "-ls" in a bunch of files...
	Try a "grep -ls *" -- it hangs up waiting for you to
	type something.  Maybe "grep \-ls *"?   Same result -- the
	shell eats the '\'.  But it DOES work to say "grep \\-ls *".

	But it does NOT work to say "rm \\-ls".


	Just a modest dose of the countless reasons why my xload window's
	slogan says "Give Me Liberty or Give Me Unix!".


----------------
Paul Raveling
Raveling@isi.edu

guy@auspex.UUCP (Guy Harris) (03/14/89)

>Now on any other UNIX system all I have to do is issue the
>command "rm -i *".

I tried it under SunOS and it didn't work, either.  The problem is that,
if "-ls" is the first file name, the command looks to the system like:

	rm -i -ls ...

and UNIX programs generally will *not* treat only the first argument
beginning with "-" as an options specifier; as such, it thinks "-ls" is
specifying the "l" and "s" flags to "rm".

The fix is that you somehow have to convince it that "-ls" isn't an
option.  There are a number of ways of doing this:

	1) pass a special flag that says "nothing after this is a flag,
	   even if it begins with "-".  The BSD "rm", upon which the
	   SunOS one is based, uses "-" for this.  The HP-UNIX one is
	   probably based on the System V one, which means it may accept
	   "--" for this:

		rm -i -- *

	2) stick something in front of the "-" in "-ls".  At least one
	   overly-complex way of doing this has been presented in a
	   previous posting; a simpler way is just to prepend "./" in
	   front of it:

		rm -i ./*

jewett@hpl-opus.HP.COM (Bob Jewett) (03/14/89)

> Yes.  The  problem, of course, is that the shell is trying to  interpret
> the file name as command line options.  So, just do something to make it
> realize that it's actually the file name.

The standard way of terminating options is to use the option "--", so to
remove a file named "-ls" you could type "rm -i -- -ls".  Note that this
works for commands that adhere to the getopts standards even for arguments
which are not files, and therefore cannot be referred to like "./-ls".

Bob

pdg@hpcupt1.HP.COM (Paul Gootherts) (03/14/89)

Try:
	rm ./-ls

Paul Gootherts, Hewlett-Packard Co, hplabs!hpda!pdg

curci@stat.uucp (Ray Curci (scri)) (03/14/89)

In article <7770@venera.isi.edu> raveling@isi.edu (Paul Raveling) writes:
>In article <2087@helios.ee.lbl.gov> JEMilburn@lbl.gov writes:
>>In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>>>I seem to have stumbled across a bug that occurs on the HP. I created a file
>>Try rm "-ls".
>Paul Raveling
>Raveling@isi.edu

The usuall way to get rid of files that begin with '-' is to use the '-' 
flag in the 'rm' command.  To remove the file "-ls", you nomally enter
the command:            rm - -ls
The first dash acts as a place holder so that the rm program does not
misinterpret the "ls" as flags to the rm program.

curci@nu.cs.fsu.edu

raveling@vaxb.isi.edu (Paul Raveling) (03/15/89)

In article <7572@pyr.gatech.EDU> curci@stat.fsu.edu (Ray Curci (scri)) writes:
>In article <7770@venera.isi.edu> raveling@isi.edu (Paul Raveling) writes:
>>In article <2087@helios.ee.lbl.gov> JEMilburn@lbl.gov writes:
>>>In article <570@sdrc.UUCP> diblanch@sdrc.UUCP (Jeff Blanchet) writes:
>>>>I seem to have stumbled across a bug that occurs on the HP. I created a file
>>>Try rm "-ls".
>>Paul Raveling
>>Raveling@isi.edu
>
>The usuall way to get rid of files that begin with '-' is to use the '-' 
>flag in the 'rm' command.  To remove the file "-ls", you nomally enter
>the command:            rm - -ls
>The first dash acts as a place holder so that the rm program does not
>misinterpret the "ls" as flags to the rm program.

	This removes -ls, but it's because rm interperts the 1st -
	as a filename.  It produces a message of "rm: - non-existent"
	and $status = 2, but does remove -ls.

	A footnote on reference to my signature should be that
	none of the referenced comments were mine.  My 2 bits is that
	the most sanitary approach under Unix is "rm ./-ls".  The
	best approach for both sanitation esthetics and user-humane
	command line interfaces is to use a better operating system.


----------------
Paul Raveling
Raveling@isi.edu

rikki@macomh.UUCP (Rikki Welsh) (03/15/89)

In article <46@nisca.ircc.ohio-state.edu>, frank@hpuxa.ircc.ohio-state.edu (Frank G. Fiamingo) writes:
> To delete a file with a "-" as the first character you need to
> clearly separate that file from the command options. 

	Or just use "rm -- -ls"
-- 
		- Rikki Welsh (UUCP: grebyn!macom1!rikki)

brad@hpiacla.HP.COM (Brad Morford) (03/15/89)

I usually write a small C program such as the one below to 
remove bizzare files.

/***************************/                                

main()
{
unlink("BizarreFileName");
}

/***************************/                                

Regards,

Brad Morford  
------------------------------------------------------------------------
Hewlett-Packard Industrial Applications Center (IAC)
1266 Kifer Road, Sunnyvale, CA, 94086   
HP-UX Mail: {hpda,hpfcla}!hpiacla!brad           
             brad@hpiacla.HP.COM
HPdesk:      Brad Morford  /HP2200/06   Phone: 408-746-5233
------------------------------------------------------------------------

rdg@hpfcmr.HP.COM (Rob Gardner) (03/16/89)

Also:
  rm -ir .
  rm -- -ls
  rm ./-ls
  rm foo -ls
  /etc/unlink -ls  # as root
etc, etc.

Related stuff: how to remove a file with control characters, 
like "foovbar" but with a backspace embedded in it? 

 echo "rm foov\010bar" | sh

And there's always "ls | od -c" or "od -c ." to find out exactly
what's in the filename anyway.

Of course, you can write a C program to do any of this trivially:

main()
{
    char foo[14];

    foo[0] = 'f';
    foo[1] = 'o';
/* etc */
    foo[10] = '\0';
    unlink(foo);
}


raab

rog@hpcilzb.HP.COM (Roger Haaheim) (03/20/89)

Why not    rm -i *   and answer no to all the queries except -ls?

wk@hpirs.HP.COM (Wayne Krone) (03/24/89)

> Why not    rm -i *   and answer no to all the queries except -ls?

Because * is expanded by the shell so the argument list passed to
rm might be "-i -ls foo1 foo2".

mmcp@sdsu.UUCP ( mmcp) (03/26/89)

In article <4640014@hpirs.HP.COM> wk@hpirs.HP.COM (Wayne Krone) writes:
>> Why not    rm -i *   and answer no to all the queries except -ls?
>
>Because * is expanded by the shell so the argument list passed to
>rm might be "-i -ls foo1 foo2".

Why not simply write a C program which uses the unlink system call to
purge the file?

Syd Logan mmcp San Diego State University

robert@shangri-la.gatech.edu.gatech.edu (Robert Viduya) (03/27/89)

This has been said before and the conversation still rambled on to the point of
ridiculousness.  What's wrong with:

		rm ./-ls
		
--
Robert Viduya					   robert@shangri-la.gatech.edu
Office of Computing Services
Georgia Institute of Technology					 (404) 894-6296
Atlanta, Georgia	30332-0275

guy@auspex.UUCP (Guy Harris) (03/28/89)

>Why not simply write a C program which uses the unlink system call to
>purge the file?

Why not write a stand-alone program to read and write disk blocks, and
patch memory, and patch the directory?  Why not take out a little bar
magnet and remagnetize the disk block containing the directory entry and
the inode?

As has been stated several times, if you want to remove a file called
"-ls" you just do

	rm -- -ls

which is one hell of a lot simpler than whacking up a C program to
unlink the file....

troyb@hpdml93.HP.COM (Troy Bergstrand) (03/28/89)

I'm late into this conversation, so forgive me if I'm duplicating someone
else's reply.  To get rid of a file with a leading minus sign is best done
using a pathname (either the whole path or at least ./) 

e.g.     rm ./-ls

wk@hpirs.HP.COM (Wayne Krone) (03/28/89)

> >> Why not    rm -i *   and answer no to all the queries except -ls?
> >
> >Because * is expanded by the shell so the argument list passed to
> >rm might be "-i -ls foo1 foo2".
> 
> Why not simply write a C program which uses the unlink system call to
> purge the file?

This was all discussed in depth several weeks ago, but the easy ways
to do it are:

	rm ./-ls

	rm -- -ls	(or	rm - -ls	for BSD derived commands)

joanne@hpccc.HP.COM (Joanne Petersen) (04/12/89)

I was just wondering....

would the command  

     rm "-ls"

work?  I used that form to get rid of a file that had a trailing blank space
at the end of the name (couldn't figure out why it kept showing up in the list
but "rm" could never find it!).....

clarke@hpfcdc.HP.COM (Clarke Echols X3194) (04/13/89)

Try:

     rm ./-ls*

The shell is trying to interpret "-" as an option.

Clarke "learned that trick the hard way with some embarrassing help from
a pro who got bit by the same problem, etc., etc." Echols

HP-UX Documentation Staff
HP Fort Collins, Colorado Site

guy@auspex.auspex.com (Guy Harris) (04/15/89)

 >I was just wondering....
 >
 >would the command  
 >
 >     rm "-ls"
 >
 >work?

"rm" is incapable of distinguishing

	rm -ls

from

	rm "-ls"

All the quotes do is affect the way the shell parses the argument; the
argument is passed to the command in the same fashion.

>I used that form to get rid of a file that had a trailing blank space
>at the end of the name (couldn't figure out why it kept showing up in the list
>but "rm" could never find it!).....

That's because it wasn't "rm" that had the problem with the trailing
blank space, it was the shell.

	rm "foobar "<return>

causes the shell to pass the string "foobar " to "rm".

	rm foobar<space><return>

causes the shell to pass the string "foobar" (no trailing space) to "rm".

joanne@hpccc.HP.COM (Joanne Petersen) (04/18/89)

Thanks to all who wrote/e-mailed me that my "suggestion" wouldn't work, and
why.... and what *would*.

craig@hpausla.HP.COM (Craig Ryan) (04/27/89)

Two ways:

1. Amazing as it seems, rm actually adheres to the '--' standard so as
   mentioned so many times in the above responses,

	rm -- -ls

2. If ls -i gives

	12000 -ls 	12332 .... etc

   then use

	find . -inum 12000 -exec rm {} \;

jeffa@hpmwtd.HP.COM (Jeff Aguilera) (04/29/89)

>>  1. Amazing as it seems, rm actually adheres to the '--' standard so as
>>     mentioned so many times in the above responses,
>>  
>>      rm -- -ls

    <fu> bar $ strings `whence rm` | fgrep -c getopt
    2

So it works --- for the twenty-seventh time.  But how standard is getopt?  The 
double dash won't work with mv:

    <fu> bar $ strings `whence mv` | fgrep -c getopt
    0

>>  2. If ls -i gives
>>  
>>      12000 -ls   12332 .... etc
>>  
>>     then use
>>  
>>      find . -inum 12000 -exec rm {} \;

This works because find passes ./-ls to rm, so why not do that directly?

Giving a path works with mv too, as in

    <fu> bar $ mv ./-ls ./-rm

Ah, ha! We found the standard buried among the rubble.  If you want a nice
long list of programs that don't use that wonderful getopt standard, try

    #!/bin/sh
    : getopt : just say no
    for file in /bin/* /usr/bin/*
    do
        test -x $file -a `strings $file | fgrep -c getopt` -gt 0 || echo $file
    done

Here are some highlights of the 332 programs on my machine that do not use 
getopt:

    /bin/ar           /bin/echo         /bin/nm           /bin/wc
    /bin/cdb          /bin/ed           /bin/nohup        /bin/xd
    /bin/chgrp        /bin/find         /bin/od           /usr/bin/awk
    /bin/chmod        /bin/gprof        /bin/rmdir        /usr/bin/ex
    /bin/chown        /bin/head         /bin/sed          /usr/bin/man
    /bin/cp           /bin/ksh          /bin/sh           /usr/bin/tar
    /bin/cpio         /bin/ld           /bin/sleep        /usr/bin/vedit
    /bin/csh          /bin/mkdir        /bin/sort         /usr/bin/vi
    /bin/date         /bin/mt           /bin/su           /usr/bin/yacc
    /bin/diff         /bin/mv           /bin/sync         /usr/bin/zcat
    /bin/du           /bin/nice         /bin/tail

--------
j "standards are gooder than good" a