[SunHELP] stupid error

William W. Arnold sunhelp at sunhelp.org
Wed Feb 7 12:42:08 CST 2001


David Bishop writes ---
>How can you delete a file that is named -al?  Being stupid, I forgot what I
>was doing and typed 'touch ls -al'.  Now, rm and mv both refuse to touch the
>file, whether I quote it, double-quote it, backslash escape it, or stand on
>my head, claiming that -al are illegal arguments.  Help!

rm ./-al

Just remember that the arguments are interpreted by the command (rm or mv)
but all the quoting/double-quoting/escaping etc is for the benifit of the shell
and is removed before the command sees it.

FAQ on comp.unix.questions

Subject: How do I remove a file whose name begins with a "-" ?
Date: Thu Mar 18 17:16:55 EST 1993

2.1)  How do I remove a file whose name begins with a "-" ?

      Figure out some way to name the file so that it doesn't begin
      with a dash.  The simplest answer is to use

            rm ./-filename

      (assuming "-filename" is in the current directory, of course.)
      This method of avoiding the interpretation of the "-" works with
      other commands too.

      Many commands, particularly those that have been written to use
      the "getopt(3)" argument parsing routine, accept a "--" argument
      which means "this is the last option, anything after this is not
      an option", so your version of rm might handle "rm -- -filename".
      Some versions of rm that don't use getopt() treat a single "-"
      in the same way, so you can also try "rm - -filename".

-- 
-billy-  warnold at vipnet.org



More information about the SunHELP mailing list