DEV Community

Discussion on: Deleting files that start with a hyphen in Bash

Collapse
 
_morgan_adams_ profile image
morgana

You would think, but that's not the case. At least not in bash. I haven't tried in other shells.

morgana@DESKTOP-23M0CRD:~/testrm$ ll
total 0
-rw-rw-rw- 1 morgana morgana 0 Jan 31 17:13 -h
morgana@DESKTOP-23M0CRD:~/testrm$ rm \\-h
rm: cannot remove '\-h': No such file or directory
morgana@DESKTOP-23M0CRD:~/testrm$ rm \-h
rm: invalid option -- 'h'
Try 'rm ./-h' to remove the file '-h'.
Try 'rm --help' for more information.
morgana@DESKTOP-23M0CRD:~/testrm$
Collapse
 
vezyank profile image
Slava

Whack. Works on my machine.

Thread Thread
 
_morgan_adams_ profile image
morgana

Which shell are you running? Version? I would like to try it out.

Thread Thread
 
vezyank profile image
Slava

Ah that might be it. I’m on zsh. I never really encountered actual shell differences before.