2

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?

3
  • 3
    Please copy/paste Terminal content as text, it's much easier to read that way.
    – nohillside
    Mar 17 at 8:17
  • The "weird file" is a temporary file that is created by Word while the original file (which has a similar name without the ~$ prefix) is open. It is supposed to disappear when you close the file.
    – jcaron
    Mar 17 at 15:24
  • @jcaron That's what I expected. However, I didn't open or keep a Word file with the file name.
    – Veck Hsiao
    Mar 18 at 7:21
4

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
% 
2
  • 1
    man bash/Special Parameters: "Expands to the current option flags as specified upon invocation, by the set builtin command, or those set by the shell itself (such as the -i option)"
    – nohillside
    Mar 17 at 7:17
  • 1
    Thanks, everyone. I see @nohillside provided a nice hint so I try to do with this: rm \~\$-VB6程式.docx. And it works. The file was removed successfully.
    – Veck Hsiao
    Mar 18 at 7:19

You must log in to answer this question.

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