How to delete a file with prefix `~$`

command linedeletingterminal

I use the command ls in a terminal. I found this wired file with the prefix ~$.
enter image description here

When I was trying to remove it, the terminal responded No such file or directory.
enter image description here

I even tried renaming it, but it still showed the same error.
enter image description here

How do I successfully remove or file the file?

Best Answer

Because the filename contains $-, you need to quote the filename when using the rm command, and other commands, as the $- unquoted is being expanded to a name other then the actual filename and is why the file isn't been found.

Terminal command examples:

% touch '~$-foobar'
% ls ~$-foobar    
zsh: no such user or named directory: 569XZilmsfoobar
% ls '~$-foobar'   
~$-foobar
% rm ~foobar       
zsh: no such user or named directory: foobar
% rm '~$-foobar'   
% 
% ls '~$-foobar'
ls: ~$-foobar: No such file or directory
%