Unix problem

Daniel A. Graifer dag at fciva.FRANKCAP.COM
Tue Apr 23 21:52:37 AEST 1991


In article <6238 at beryl12.UUCP> mostek at motcid.UUCP (Frank B. Mostek) writes:
>wangjw at 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 at uunet.uu.net



More information about the Comp.unix.misc mailing list