Page 1 of 1

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

Posted: Mon Mar 28, 2011 2:59 pm
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. ;)

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

Posted: Fri Dec 06, 2013 2:42 am
by ^rooker
Another option is to rename the file.
Like this:

Code: Select all

$ mv ./--filename new_filename