How to delete a file with prefix `~$`
I use the command ls
in a terminal. I found this wired file with the prefix ~$
.
When I was trying to remove it, the terminal responded No such file or directory
.
I even tried renaming it, but it still showed the same error.
How do I successfully remove or file the file?
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
%