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?

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

5 Answers 5


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

rm \!\!

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


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

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

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

set +o histexpand

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). Jan 19, 2015 at 14:07
  • What does rm -rf '&$dir' is supposed to do?
    – jimmij
    Jan 19, 2015 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, 2015 at 14:39

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. Jan 19, 2015 at 17:29
  • @PeterSchneider Why is answering a question, and the giving a tip considered mean? It was with good intent. Jan 19, 2015 at 21:25

Not the answer you're looking for? Browse other questions tagged .