4

This question already has an answer here:

Out of rage, I quit vim by using :wq!!!. This created a file named !!.

Given that !! references the previous command, attempting to interact with it yields interesting results.

I tried rm ./!! and rm -- !!. Both would pull in the previous command (as it should).

An easy solution is to simply start a shell that doesn't treat !! like anything special, but that's too easy.

How can I properly interact with the file in bash?

marked as duplicate by Gilles bash Jan 19 '15 at 18:01

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    rm -- '!!' or rm -- \!\! Both is workable on bash 4.3.11 – Costas Jan 19 '15 at 13:51
5

You can remove file with name like !!, just escape it:

rm \!\!

or just rm !<TAB> -> rm \!\!

1

With Bash, you can use rm -- '!!'

$ cat '!!'
Lorem ipsum dolor sit amet
$ ls 
!!
$ rm '!!'
$ ls 
$
0

Excape the "!" character with backslash. Or disable history expansion.

set +o histexpand
0

I always find it easier to wrap file/directory names created with special characters using single quotes:

rm '!!'
rm -rf '&$dir'
  • For !!, that works in bash, but not in (t)csh (where that history expansion feature comes from). – Stéphane Chazelas Jan 19 '15 at 14:07
  • What does rm -rf '&$dir' is supposed to do? – jimmij Jan 19 '15 at 14:13
  • rm -rf '&$dir' is for special character created directories. I have come across users who created directories as such from poor cmdline syntax. The -f to force and not prompt, but that can be omitted if you wish to constantly be prompted. – devnull Jan 19 '15 at 14:39
0
\!\!

You should get a terminal which can automate this for you, in my Terminal.app I can drop anything with a name of like

√ƒ¸[|¸ƒ¸|[∂[ƒ√[[ƒ||[]√ƒ√¸•[]¸√[®¸@£|[¸|[]]ƒ¸é[

And it will escape it for me automatically. Consider getting that, to avoid asking these types of questions in the future.

  • 2
    That was unnecessarily mean (considering that the question was asked partly out of general curiosity since the OP had a solution at hand already). Also, in many contexts I do really not want the terminal to interfere with what I type because even the smartest terminal is so much more stupid than I am, short of the singularity. And after the singularity more than ever I really really do not want the terminal to interfere either, now that I think of it. – Peter A. Schneider Jan 19 '15 at 17:29
  • @PeterSchneider Why is answering a question, and the giving a tip considered mean? It was with good intent. – DisplayName Jan 19 '15 at 21:25

Not the answer you're looking for? Browse other questions tagged or ask your own question.