How to delete a file whose name begin with -

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

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?
 

im

Member

Reaction score: 37
Messages: 87

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
 
OP
H

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

So simple, im, thanks. Full path.

Buit still I wonder, why names got by glob are still seen as options. That may be risky.
 

Zirias

Daemon

Reaction score: 1,182
Messages: 2,149

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.
 

Zirias

Daemon

Reaction score: 1,182
Messages: 2,149

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.
 

Zirias

Daemon

Reaction score: 1,182
Messages: 2,149

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.
 
OP
H

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

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.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,987
Messages: 36,922

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'.
 
OP
H

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

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?
 

Zirias

Daemon

Reaction score: 1,182
Messages: 2,149

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):
 
OP
H

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

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.
 

Zirias

Daemon

Reaction score: 1,182
Messages: 2,149

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.
 
OP
H

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

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.
 

SirDice

Administrator
Staff member
Administrator
Moderator

Reaction score: 10,987
Messages: 36,922

Don't claim something is a bug just because you misunderstood something.
 
OP
H

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

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.
 
OP
H

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

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".
 
OP
H

hruodr

Aspiring Daemon

Reaction score: 205
Messages: 772

Quoting is not globing. BTW, Why were you teaching methods for escape totaly out of context?
 
Top