home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!ucbvax!mtxinu!sybase!hsc
- From: hsc@sybase.com (Howard Cohen)
- Newsgroups: comp.unix.shell
- Subject: Re: How can I rm a file with a '&' ????
- Message-ID: <22856@sybase.sybase.com>
- Date: 26 Aug 92 23:01:39 GMT
- References: <S025H1G@obh.in-berlin.de> <28300002@tisdec.tis.tandy.com> <1992Aug24.081355.6563@physiol.su.OZ.AU>
- Sender: news@Sybase.COM
- Organization: Sybase, Inc.
- Lines: 42
-
- Ok, some facts. It can be hard to remove files that contain certain
- characters, becuase of side-effects of their special meanings. For example,
- try to remove a file that begins with a dash (-). Surprise! Not so easy.
-
- First, I never write tools which create problem filenames. So I tend not
- to need to handle them in the tools I write. However, its easy enough to
- create problem filenames through mistakes, typos (especially from vi), etc.
- So the need does arise for me to address problem filenames.
-
- What I generally do for a one-time-only problem is to create a simple
- C program like this:
-
- main()
- {
- unlink("weirdfilename");
- }
-
- Obviously, this isn't a great solution if you need to run it on lots of
- different machines, or have lots of different files to remove. Several
- others have posted legitemate reasons to avoid proliferating tiny
- specialized C programs, and I agree with them all. I only use this
- technique when I have a single problem file to remove. Then I quickly remove
- the C source and executable. If I'd be tempted to save it, then I'd know
- I picked the wrong solution.
-
- Another useful technique is to rename the directory containing the problem
- file(s), and create a new directory by the original name. Then mv the
- files from the old directory into the new one, leaving behind what you don't
- want. This works well too, and can be done in a shell script fairly easily.
-
- Its funny though, when people ask me how to remove a strange filename, and
- I show them my unlink trick, they look pained, as though I'd made a bad pun.
- Then I can't help pointing out that this is my "main" solution to this kind
- of problem...
-
- :)
-
- Howard
- -------------------------------------------------------------------------------
- Howard "I wood if I could" Cohen
- hsc@sybase.com {pacbell,pyramid,sun,{uunet,ucbvax}!mtxinu}!sybase!hsc
- Sybase, Inc. 6475 Christie Avenue, Emeryville, CA 94608, 510-596-3406
-