[comp.unix.misc] Unix problem

wangjw@cs.purdue.EDU (Jingwen Wang) (04/21/91)

Hi,

  I was using the X-window and somehow generated some garbage files. I
cannot remove some files because these files are named "-C", "-f" etc.
Can someone tell me how to remove these garbages? 

  Thanks.

Jingwen Wang

wangjw@cs.purdue.edu

kdeyoe@tjhsst.vak12ed.edu (Kelly DeYoe) (04/21/91)

In article <14425@medusa.cs.purdue.edu> wangjw@ifestos.cs.purdue.edu () writes:
>Hi,
>
>  I was using the X-window and somehow generated some garbage files. I
>cannot remove some files because these files are named "-C", "-f" etc.
>Can someone tell me how to remove these garbages? 
>
>  Thanks.
>
>Jingwen Wang
>
>wangjw@cs.purdue.edu


To get rid of these files, or simply be able to rename them to
something more managable, you can go to the parent directory and
manipulate them that way.  i.e.:

cd ..
rm dir/-C (assuming you started in directory dir)

and *poof*, it's gone. . .

KD

zebr360@ut-emx.uucp (Jerry Heyman) (04/22/91)

In article <1991Apr21.124135.7732@tjhsst.vak12ed.edu> kdeyoe@tjhsst.vak12ed.edu (Kelly DeYoe) writes:
|>In article <14425@medusa.cs.purdue.edu> wangjw@ifestos.cs.purdue.edu () writes:
|>>Hi,
|>>
|>>  I was using the X-window and somehow generated some garbage files. I
|>>cannot remove some files because these files are named "-C", "-f" etc.
|>>Can someone tell me how to remove these garbages? 
|>>
|>>  Thanks.
|>>
|>>Jingwen Wang
|>>
|>>wangjw@cs.purdue.edu
|>
|>
|>To get rid of these files, or simply be able to rename them to
|>something more managable, you can go to the parent directory and
|>manipulate them that way.  i.e.:
|>
|>cd ..
|>rm dir/-C (assuming you started in directory dir)
|>
|>and *poof*, it's gone. . .
|>

another way is to preface the files with ./ (for current directory) followed
by their name.  that way:

rm ./-C

works fine.  Unix expects any thing following a '-' sign to be an option
to the command invoked.  It doesn't differentiate between them and file names
that happen to be the same.

|>KD

jerry
-- 
Jerry Heyman                  by day: IBM PSP, AIX Development
zebr360@emx.utexas.edu        by nite: Adjunct Lecturer at St. Edward's Univ.

*All comments are my own and should not be construed to represent any one else

mostek@motcid.UUCP (Frank B. Mostek) (04/23/91)

wangjw@cs.purdue.EDU (Jingwen Wang) writes:

>  I was using the X-window and somehow generated some garbage files. I
>cannot remove some files because these files are named "-C", "-f" etc.
>Can someone tell me how to remove these garbages? 

Use the find command:
                                                    
find . -name "-C" -exec rm -f {} \;

I am not sure why this works and
rm -f "-C" does not work.

Any insights?
-- 
Frank Mostek			uunet!motcid!amethyst!mostek
(708)632-7191			mostek@amethyst.mot.com

kherron@ms.uky.edu (Kenneth Herron) (04/23/91)

mostek@motcid.UUCP (Frank B. Mostek) writes:

>find . -name "-C" -exec rm -f {} \;

>I am not sure why this works and
>rm -f "-C" does not work.

Because find will do the same thing the Frequently Asked Questions 
list suggests--it will execute

rm -f ./-C
-- 
Kenneth Herron                                            kherron@ms.uky.edu
University of Kentucky                                        (606) 257-2975
Department of Mathematics 
             "P.S.:  Please excuse the lateness of my reply." -- Ringo Starr

dag@fciva.FRANKCAP.COM (Daniel A. Graifer) (04/23/91)

In article <6238@beryl12.UUCP> mostek@motcid.UUCP (Frank B. Mostek) writes:
>wangjw@cs.purdue.EDU (Jingwen Wang) writes:
>
>>I cannot remove some files because these files are named "-C", "-f" etc.
>>Can someone tell me how to remove these garbages? 
>
>Use the find command:
>                                                    
>find . -name "-C" -exec rm -f {} \;
>
>I am not sure why this works and rm -f "-C" does not work.

This works because find passes the complete path from it's
starting point to the file as {}.  In this case the exec
expands as

	rm -f ./-C

The thing to remember about rm (or any other 'conforming' unix command)
is that words on the command line starting with '-' are assumed to be
options up until the first word which does not (and doesn't follow an
option which eats a word as an option value).  So the trick is to make
your dash-prefixed parameter (in this case a filename) either start with
something else (in this case ./) or to interpose another parameter. For
example
	rm fubar -C
will work;  You will just get an error message that fubar doesn't exist
(assuming it doesn't :-)).  Some programs, such as sh, will recognize
a lone '-' as forcing the end of option processing. Rm doesn't, but
recognizes that '-' is not a valid option, and assumes it's a filename so
	rm - -C
will work, but give the error message "'-' non-existant".

Dan
-- 
Daniel A. Graifer			Coastal Capital Funding Corp.
Sr. Vice President, Financial Systems	7900 Westpark Dr. Suite A-130
(703)821-3244				McLean, VA  22102
uunet!fciva!dag				fciva.FRANKCAP.COM!dag@uunet.uu.net

jik@athena.mit.edu (Jonathan I. Kamens) (04/24/91)

In article <598@fciva.FRANKCAP.COM>, dag@fciva.FRANKCAP.COM (Daniel A. Graifer) writes:
|> Some programs, such as sh, will recognize
|> a lone '-' as forcing the end of option processing. Rm doesn't, but
|> recognizes that '-' is not a valid option, and assumes it's a filename so
|> 	rm - -C
|> will work, but give the error message "'-' non-existant".

On a BSD4.3 system:

	% echo > -test
	% rm - -test
	%

On an Ultrix 3.1 system:

	% echo > -test
	% rm - -test
	%

On an A/UX system:

	% echo > -test
	% rm - -test
	%

On an AIX 1.2 system:

	% echo > -test
	% rm - -test
	%

Furthermore, the BSD4.3 and Ultrix rm(1) man pages both mention the '-'
option.  The AIX man page claims that the option is '--' rather than '-'; I
suspect that support for '-' was left in for backward compatibility.  The A/UX
man page doesn't mention '-', but that doesn't surpise me.

The point I'm trying to make, in case you haven't figure it out yet, is that
rm(1) has recognized '-' as a signal for the end of the command arguments for
a *long* time.  In fact, I was under the impression that the original version
of rm snarfed by Berkeley from AT&T had this feature.

If you've got a version of rm that doesn't recognize '-' as an option
signalling the end of command-line options, then either (a) your rm uses '--'
instead of '-', and decided not to support '-', or (b) you've got a really
broken version of rm.

One more thing -- the question of how to remove files whose names start with
'-' is the FIRST question answered in the comp.unix.questions FAQ posting.  It
would be nice if people wouldn't post answers in the comp.unix newsgroups
without first reading and being familiar with the contents of the FAQ posting.
I wouldn't post this flame to the net if it weren't for the fact that I'm
already posting to the net to correct a mistake, but now that I'm posting on
the subject, I figured I might as well mention the FAQ.  The instructions
appended to the end of this message explain how to get a copy of the FAQ.

-- 
Jonathan Kamens			              USnail:
MIT Project Athena				11 Ashford Terrace
jik@Athena.MIT.EDU				Allston, MA  02134
Office: 617-253-8085			      Home: 617-782-0710
-- 
        Subject: Frequently Asked Questions about Unix - with Answers [Monthly posting]
        Newsgroups: comp.unix.questions

        Available via anonymous ftp from pit-manager.mit.edu (18.72.1.58)
        in the file

        /pub/usenet/comp.unix.questions/Frequently_Asked_Questions_about_Unix_-_with_Answers_[Monthly_posting]

        Available from mail-server@pit-manager.mit.edu by sending a message
        containing

        send usenet/comp.unix.questions/Frequently_Asked_Questions_about_Unix_-_with_Answers_[Monthly_posting]

        Send a message containing "help" to get general information about the
        mail server.

csu@alembic.acs.com (Dave Mack) (04/25/91)

In article <6238@beryl12.UUCP> mostek@motcid.UUCP (Frank B. Mostek) writes:
>wangjw@cs.purdue.EDU (Jingwen Wang) writes:
>
>>  I was using the X-window and somehow generated some garbage files. I
>>cannot remove some files because these files are named "-C", "-f" etc.
>>Can someone tell me how to remove these garbages? 
>
>Use the find command:
>                                                    
>find . -name "-C" -exec rm -f {} \;

Many versions of rm(1) support the "-" flag, as in

	"rm - -C"

which tells rm that the next argument is not an option even if it
starts with a dash. Check your local man page.

>I am not sure why this works and
>rm -f "-C" does not work.

Because the shell removes the quotes before execing rm. It
works in find because find interprets the argument after
-name as a filename even if it begins with a "-".

-- 
Dave Mack