Try the single-quotes version:
Single quotes remove just about all magic.
Double-quotes keep the magic in bounds (for example: rm "Program Files/*" understands that the directory name is "Program Files" and not delete file named Program and files in directory named Files)
Then there's the "backticks":
ls -l `which bash`
will execute command "which bash" and thus list the file characteristics of the bash command.
[ October 27, 2004: Message edited by: Tim Holloway ]
I actually had a directory created as "-test" and a file "-"
I used these command to remove, hope this will also help others too.
rm ./-filename --> Files that begin with a dash can be removed by typing
rm -- -filename --> Files that begin with a dash can be removed by typing
rm - -filename --> Files that begin with a dash can be removed by typing
rm -i * --> A file with no filename.This will prompt and press yes for blank file
-- is quite common to indicate the end of command line options so you can safely use - to start an actual string in other command line arguments (a file name in this case).
Another option is to use \ to escape a single character:
$ rm \-test
What I generally do, since I've always got an Emacs window open, is use Emacs' "dired" mode, which lets you mark and delete any file no matter how crazy its name is.
Since this is JavaRanch, another alternative, of course, is something like
Originally posted by Ernest Friedman-Hill:
The "--" trick is the one that will work; no kind of quoting or escaping will mater for filenames that start with a dash, since those approaches merely prevent interpretation by the shell, and dash isn't a character that is interpreted specially by the shell in the first place: it's the command (rm, for example0 that thinks "-test" looks like an argument....
Good point. Thanks for pointing that out, Ernest