Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!uunet!fciva!dag From: dag@fciva.FRANKCAP.COM (Daniel A. Graifer) Newsgroups: comp.unix.misc Subject: Re: Unix problem Message-ID: <598@fciva.FRANKCAP.COM> Date: 23 Apr 91 11:52:37 GMT References: <14425@medusa.cs.purdue.edu> <6238@beryl12.UUCP> Reply-To: dag@fciva.UUCP (Daniel A. Graifer) Organization: Coastal Capital Funding Corp., McLean, VA Lines: 39 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