Deleting a file name beginning with a hyphen

Federico Voges ftc
Thu Oct 20 05:01:11 PDT 2005


jamesm at jamesmcdonald.id.au wrote:

>As you can see from the following I have finally deleted this annoying
>file with the name `-C' I was trying to delete it using \ to escape the -
>characters. I was just on the verge of emailing Y'ALL when I had a final
>go and
>found that you have to specify the full path.... sigh live and learn
>
>
>[root at apf-ma-qad01 root]# ls
>anaconda-ks.cfg  -C                evolution    install.log.syslog
>subversion
>bin              desktop28install  install.log  mbox
>[root at apf-ma-qad01 root]# rm '-C'
>rm: invalid option -- C
>Try `rm --help' for more information.
>[root at apf-ma-qad01 root]# rm '\-C'
>rm: cannot lstat `\\-C': No such file or directory
>[root at apf-ma-qad01 root]# rm "\-C"
>rm: cannot lstat `\\-C': No such file or directory
>[root at apf-ma-qad01 root]# rm -C
>rm: invalid option -- C
>Try `rm --help' for more information.
>[root at apf-ma-qad01 root]# rm \\-C
>rm: cannot lstat `\\-C': No such file or directory
>[root at apf-ma-qad01 root]# rm /root/-C
>rm: remove regular file `/root/-C'? y
>[root at apf-ma-qad01 root]#
>  
>
rm \-C
and
rm -- -C
should have worked too :)

In some cases you could have also used:
rm ?C

Cheers,
Fed.


More information about the Linux-users mailing list