3 ms·
>Another common footgun is not including a double dash ('--') at the end of command options so that the following filename won't be interpreted as an option whe
by vram22 3y ago
>Another common footgun is not including a double dash ('--') at the end of command options so that the following filename won't be interpreted as an option when it begins with a dash.
Yes. And if you have a file name that begins with a dash, and you want to delete it, you can use this command:
$ rm -- -filename
where -filename is that file. Here, the -- (double dash) means "end of the command-line options", so any argument after that is treated as a non-option argument, in this case, a filename for rm to delete.
This -- (double dash) works with many Unix commands. It was introduced relatively early on in Unix history, after the issue of filenames starting with a dash was found.
Although it is more likely that you would want to rename the file, to remove the dash from the name.
- ndsipa_pomu 3y agoAnother way of working around the issue of filenames beginning with a dash is to just put "./" in front of it. That's not always useful in scripts though if you don't know whether the variable will be a relative or absolute filename (though you could check for that easily enough).