home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / shell / 3721 < prev    next >
Encoding:
Text File  |  1992-08-31  |  2.3 KB  |  54 lines

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