Unix Shell - removing file starting with a dash

This is Interesting: Free IT Magazines  
Home > Archive > Unix Shell > March 2004 > removing file starting with a dash





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author removing file starting with a dash
Neil Zanella

2004-03-29, 5:37 pm

Hello,

I have a directory which contains a file whose name begins with a dash (not
quite sure how it got there, but probably some script I was writing placed
it there while I was debugging it).

So, how do I remove it. I tried issuing 'rm -i *' for interactive mode but
the result was the following (the file itself appears to be named -foo):

rm: invalid option -- foo
Try `rm --help' for more information.

The same happens with lots of other commands I try. The obvious solution is to
copy all other files to some other directory, remove the directory, and then
rename the new directory to the name of the removed one.

However, I would like to know of a real solution, i.e., how to remove the
file directly without having to go through this tedious process.

Thanks!

Neil
LANkrypt0

2004-03-29, 5:37 pm

On Mon, 29 Mar 2004, Neil Zanella wrote:
[color=darkred]

You should be able to use:
rm -- -filename

--

+=======+==+=======>
LANkrypt0 :: aa#2118
"GzA SOb FE6 OQQ:
pFp zAM 6Fn MS6 QUb 6po J6."
- KAQ QAO 08z Om6 SZ6 Oo6, wO0 Q6p
postcount=$(($postcount+1))
+=========================+======>
Chris F.A. Johnson

2004-03-29, 5:37 pm

On Mon, 29 Mar 2004 at 21:52 GMT, Neil Zanella wrote:
> Hello,
>
> I have a directory which contains a file whose name begins with a dash (not
> quite sure how it got there, but probably some script I was writing placed
> it there while I was debugging it).
>
> So, how do I remove it. I tried issuing 'rm -i *' for interactive mode but
> the result was the following (the file itself appears to be named -foo):
>
> rm: invalid option -- foo
> Try `rm --help' for more information.
>
> The same happens with lots of other commands I try. The obvious solution is to
> copy all other files to some other directory, remove the directory, and then
> rename the new directory to the name of the removed one.
>
> However, I would like to know of a real solution, i.e., how to remove the
> file directly without having to go through this tedious process.


rm ./-foo

Or:

rm -- -foo


(This should be added to the FAQ.)


--
Chris F.A. Johnson http://cfaj.freeshell.org/shell
========================================
===========================
My code (if any) in this post is copyright 2004, Chris F.A. Johnson
and may be copied under the terms of the GNU General Public License
joe@invalid.address

2004-03-29, 6:37 pm

"Chris F.A. Johnson" <c.fa.johnson@rogers.com> writes:

> On Mon, 29 Mar 2004 at 21:52 GMT, Neil Zanella wrote:
>
> rm ./-foo
>
> Or:
>
> rm -- -foo
>
> (This should be added to the FAQ.)


Will do.

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Fred L. Kleinschmidt

2004-03-29, 6:37 pm



Neil Zanella wrote:
>
> Hello,
>
> I have a directory which contains a file whose name begins with a dash (not
> quite sure how it got there, but probably some script I was writing placed
> it there while I was debugging it).
>
> So, how do I remove it. I tried issuing 'rm -i *' for interactive mode but
> the result was the following (the file itself appears to be named -foo):
>
> rm: invalid option -- foo
> Try `rm --help' for more information.
>
> The same happens with lots of other commands I try. The obvious solution is to
> copy all other files to some other directory, remove the directory, and then
> rename the new directory to the name of the removed one.
>
> However, I would like to know of a real solution, i.e., how to remove the
> file directly without having to go through this tedious process.
>
> Thanks!
>
> Neil

As others have said, use the "--" option. Or, if you try this again next
year and can't remember the "--" option, just try putting some nonsense
name first:
rm -foo
Of course rm will complain that it can't find xxxxxxxxxxxxxxxx , but it
will still remove -foo.

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
Fred L. Kleinschmidt

2004-03-29, 6:37 pm



Neil Zanella wrote:
>
> Hello,
>
> I have a directory which contains a file whose name begins with a dash (not
> quite sure how it got there, but probably some script I was writing placed
> it there while I was debugging it).
>
> So, how do I remove it. I tried issuing 'rm -i *' for interactive mode but
> the result was the following (the file itself appears to be named -foo):
>
> rm: invalid option -- foo
> Try `rm --help' for more information.
>
> The same happens with lots of other commands I try. The obvious solution is to
> copy all other files to some other directory, remove the directory, and then
> rename the new directory to the name of the removed one.
>
> However, I would like to know of a real solution, i.e., how to remove the
> file directly without having to go through this tedious process.
>
> Thanks!
>
> Neil

As others have said, use the "--" option. Or, if you try this again next
year and can't remember the "--" option, just try putting some nonsense
name first:
rm xxxxxxxxxxxxxxxx -foo
Of course rm will complain that it can't find xxxxxxxxxxxxxxxx , but it
will still remove -foo.

--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Common User Interface Services
M/S 2R-94 (206)544-5225
joe@invalid.address

2004-03-29, 9:35 pm

joe@invalid.address writes:

> "Chris F.A. Johnson" <c.fa.johnson@rogers.com> writes:

[color=darkred]

Added it and reposted the FAQ along with another change.

Joe
--
If people don't want to come out to the ballpark, nobody's going
to stop them.
- Yogi Berra
Brian Gough

2004-03-30, 5:37 am

nzanella@cs.mun.ca (Neil Zanella) writes:

> I have a directory which contains a file whose name begins with a dash (not
> quite sure how it got there, but probably some script I was writing placed
> it there while I was debugging it). So, how do I remove it....


One way: rm ./-foo

See the manual for the GNU file utilities for a discussion of the
issue (on a GNU/Linux system it is usually available with the command
"info rm"). There is a lot of other useful stuff in there too.

HTH
--
Brian Gough

Network Theory Ltd,
Publishing Free Software Manuals --- http://www.network-theory.co.uk/
Kenny McCormack

2004-03-30, 8:39 am

In article <m3zn9zccap.fsf@invalid.address>, <joe@invalid.address> wrote:
>joe@invalid.address writes:
>
>
>
>Added it and reposted the FAQ along with another change.


I thought (seriously) that this *was* in the FAQ already.

In fact, I thought it was *the* FAQ.

Web Surfer

2004-03-30, 11:37 am

[This followup was posted to comp.unix.shell]

In article <b68d2f19.0403291352.e6b6eb3@posting.google.com>,
nzanella@cs.mun.ca says...
> Hello,
>
> I have a directory which contains a file whose name begins with a dash (not
> quite sure how it got there, but probably some script I was writing placed
> it there while I was debugging it).
>
> So, how do I remove it. I tried issuing 'rm -i *' for interactive mode but
> the result was the following (the file itself appears to be named -foo):
>
> rm: invalid option -- foo
> Try `rm --help' for more information.
>
> The same happens with lots of other commands I try. The obvious solution is to
> copy all other files to some other directory, remove the directory, and then
> rename the new directory to the name of the removed one.
>
> However, I would like to know of a real solution, i.e., how to remove the
> file directly without having to go through this tedious process.
>
> Thanks!
>
> Neil



rm ./-foo

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com