Search code examples
linuxbashrm

Removing a file called ~


I accidentally named a file ~ when I was trying to move it to my home directory. And now in my / there is a file called ~ and I have no idea how I would remove it.

How would I remove a file that I accidentally renamed ~?


Solution

  • Put the filename in quotes:

    rm '~'
    

    You can follow the bash manual:

    https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html

    If a word begins with an unquoted tilde character (‘~’), all of the characters up to the first unquoted slash (or all characters, if there is no unquoted slash) are considered a tilde-prefix. ...