How to delete a file whose name begin with -

I have a file -tmp-3. The command line comands interpret the - as a flag even if I write ls *tmp-3.

Is this a big in (Free)BSD?
 
rm ./-filename works for me.

Read the manual rm(1)
Code:
NOTES
     The rm command uses getopt(3) to parse its arguments, which allows it to
     accept the `--' option which will cause it to stop processing flag
     options at that point.  This will allow the removal of file names that
     begin with a dash (`-').  For example:

           rm -- -filename

     The same behavior can be obtained by using an absolute or relative path
     reference.  For example:

           rm /home/user/-filename
           rm ./-filename
 
Well, the full path is a workaround, the canonic marker for "end of options" in a Unix command is --, so everything after that is treated as "positional argument", even if it starts with a dash.
Buit still I wonder, why names got by glob are still seen as options. That may be risky.
What do you mean with "got by glob"? It's on the commandline and - is the special character for an option. It was always that way on any Unix-like system.
 
es, but tcsh and sh are doing that. It is a bug in my oppinion.
It is specified in POSIX that globs are expanded by the shell (and if you want to pass them unexpanded to a command, you have to escape them). Your "opinion" doesn't count here.
 
Methods for escape something in a shell are putting it in double-quotes, single-quotes, or (for single characters) put a backslash in front of it. For details read sh(1).

Be aware neither ls nor rm understand globs.
 
Well I see the ratio and to do something else would make things "unnecessarily" complicated.
Undesired behaviour is also not the right word. It remains risky.
 
You escape characters using the backslash \. To get a literal question mark for example: touch \?. Or use single quotes, touch '?'. Single and double quotes are treated differently too. There's a difference between touch "$foo" and touch '$foo'.
 
Methods for escape something in a shell are putting it in double-quotes, single-quotes, or (for single characters) put a backslash in front of it.
All that does not work in the case treated here. Perhaps it is you who have to learn something?
 
Are you kidding? You're nagging about "original Unix behavior" pretty often, but obviously have no clue how things work. I TOLD you in the same post, that neither ls nor rm understand globs!

The behavior of FreeBSD is POSIX compliant, and of course you will find the same behavior in any other Unix-like system (if it isn't broken).

Specifically, the double-dash is documented here (guideline 10):
 
but obviously have no clue how things work.
I am not as perfect as you are. Thats all.

BTW. Your proposal of quoting seems to be based on my own lapsus. But anyway, you are sure better, I am
not a computer scientist and also do not want to be one.
 
Not knowing things isn't a problem at all, but basing strong opinions ("bug", "you have to learn something", etc…) on a wrong understanding is.
 
but basing strong opinions ("bug", "you have to learn something", etc…) on a wrong understanding is.
Your strong opinions are always based on right understanding, because you always understand things right
and your understanding will never appear later to be wrong.
 
The behavior of FreeBSD is POSIX compliant, and of course you will find the same behavior in any other Unix-like system (if it isn't broken).

Specifically, the double-dash is documented here (guideline 10):
Utility Conventions
From all your interventions, this is the only what I appreciate and thank. Also for reminding me that the
glob is done by shell (lapsus) and hence the command would still behave in the same way. Note that
by recommending quoting you fell in the very same lapsus.
 
Don't claim something is a bug just because you misunderstood something.
But for not doing that, you must know that you misunderstood something, and hence it would not
be misunderstanding.

And I did not claim it is a bug, I wrote "in my opinion it is a bug", and that is a call to contradict it.

Also not a strong opinion was the question: "Perhaps it is you who have to learn something?".
Reasons: (1) there is always something to learn, (2) Zirias do not need to learn anything, but
I wrote for that reason "perhaps".
 
Back
Top