Search code examples
bashunixvimwindows-subsystem-for-linux

Remove file starting with double ampersand and exclamation


I have a file called && !!

How do I delete this file?

On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
  (use "git add <file>..." to include in what will be committed)

    && !!
rm -- "&& !!"

Result:

rm: cannot remove '&& git st': No such file or directory

As you've might guessed, git st is my way of git status.

How did I get here?

  1. Open Vim

  2. :e && !!

  3. :wq


Solution

  • Your rm -- "&& !!" attempt failed because history expansion replaced !! by the previously executed command. You can avoid this by quoting your file name in single quotes since you don't need the content to be expanded:

    rm -- '&& !!'
    

    History expansion has tripped me up more often than I liked and I never found a use for the feature, so I chose to disable it by adding set +H to my .bashrc file.