removing a file with hyphens

John Costello cos at
Mon Jun 11 22:43:45 BST 2007

On Thu, 7 Jun 2007, Paul Orrock wrote:
> Hi,
> So for reasons I won't go into I ended up with a file like this
> -rw-r--r--   1 paulo paulo       0 2007-05-21 14:23 -----Original
> which I didn't want, so I tried the following :

> Then I tried unlink('-----Original') using perl and it worked fine.
> I'm glad that it did but I'm curious as to why ?
> My second question is how do non perl people do it ?

I see that others have directed you to 'man rm', which is good to know
about should you ever interview as a sysadmin.

unlink on Solaris works, because it doesn't take any arguments, and 
therefore views anything starting with a '-' as a valid filename.  rm 
expects arguments beginning with '-' to be one of its arguments, or a 

Looks like newer versions of Linux have unlink (RH 7.x series doesn't
appear to have the command, though that could just be the system I looked
at, but FC series does).  That version does take arguments of the fashion
of --help and --version, so you would have to use `unlink ./--help` to
remove a file named --help.

unlink in perl appears to use the unlink system call.

More information about the mailing list