Delete files with hyphen/dash at the beginning of their name

Step-by-Step descriptions of how to do things.
Post Reply
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Delete files with hyphen/dash at the beginning of their name

Post by ^rooker »

[PROBLEM]
Sometimes it happens:
You've created a file with a 'minus' aka 'hyphen' character at the beginning of its filename.
For example:
-bla.txt
If you try to remove that file using regular commands like 'rm' or maybe even 'mv', the filename will mistakingly be interpreted as control argument, and you'll get an error like this:
rm: invalid option -- b
Try `rm --help' for more information.
[SOLUTION]
Add a path to the filename to "defuse" the hyphen at the beginning. Like this:

Code: Select all

rm -r ./bla.txt
That's it. ;)
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
User avatar
^rooker
Site Admin
Posts: 1481
Joined: Fri Aug 29, 2003 8:39 pm

Re: Delete files with hyphen at the beginning of their name

Post by ^rooker »

Another option is to rename the file.
Like this:

Code: Select all

$ mv ./--filename new_filename
Jumping out of an airplane is not a basic instinct. Neither is breathing underwater. But put the two together and you're traveling through space!
Post Reply