Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Nov 1998 08:32:44 +0000
From:      Mark Ovens <marko@uk.radan.com>
To:        Anand Buddhdev <arb@anand.org>
Cc:        "Leonard C." <leonardc9@usa.net>, questions@FreeBSD.ORG
Subject:   Re: How to delete files starting with "-"?
Message-ID:  <365A6F2C.C114F38@uk.radan.com>
References:  <v04011709b2801982e8b9@[10.0.0.2]> <19981124111248.B11637@iconnect.co.ke>

next in thread | previous in thread | raw e-mail | index | archive | help
Anand Buddhdev wrote:
> 
> On Tue, Nov 24, 1998 at 12:12:25AM -0800, Leonard C. wrote:
> 
> > I accidentally created a file starting with a dash, and can't seem to
> > delete it.  mv, cp, and rm all interpret the dash as an argument.
> >
> > If "-foo" is the name of the file, I've tried "-foo", '-foo', and \-foo,
> > but none of them work since these just affect the shell rather than the
> > actual parsing of the command itself.  Any ideas?  This is driving me
> > *absolutely* crazy!
> 
> rm ./-foo
> 
> The dot-slash causes the shell not to treat the hyphen specially. funnily
> though,
> 

Because ``./-foo'' is a single string and therefore ``-'' is not the
first character. ``-'' only has a special meaning at the start of an
argument, i.e. options.

> rm '-foo' should also work,

It won't. The shell will strip the quotes so ``rm'' gets ``-foo'' as
an argument which, because it starts with ``-'', it tries to parse as
options with no filename, i.e. the same as typing ``rm -f -o -o''. 
There is no ``o'' option to rm and you must specify one or more
filename(s).

> unless the permissions on the file do not allow
> you to delete it. If rm ./-foo does not work, then you should look at the
> permission on the file. That may be where your problem lies.
> 
> --
> Anand
> 
> To Unsubscribe: send mail to majordomo@FreeBSD.org
> with "unsubscribe freebsd-questions" in the body of the message

-- 
  Trust the computer industry to shorten Year 2000 to Y2K. It
  was this thinking that caused the problem in the first place.

Mark Ovens, CNC Applications Engineer, Radan Computational Ltd.
Bath, Avon, England.  Sheet Metal CAD/CAM Solutions
mailto:marko@uk.radan.com    http://www.radan.com

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-questions" in the body of the message



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?365A6F2C.C114F38>