Mac Terminal – How to Get Rid of Locked Word File on Mac

macms officeterminal

There is a file on my desktop called "~$file.docx" and I can't get rid of it.

I understand (at a very low level) it is a lock file for Word, and these files have certain properties. But I just want to delete it. I deleted "file.docx" but the damn lock file remains.

I can't open it in Word. I can't do anything with in terminal (e.g. rm). But if I ls -als in my Desktop it tells me I have full permissions:

-rw-r--r--@

How do I delete this file?

Update The output of ls -@e is the same as the simple ls. I just see "~$file.docx". If I try to remove it I get an error: No such file or directory.

Update Here is the output to the other ls call:

-rw-r--r--@  1 UserName  staff  hidden       162 Jul 31  2018 ~file.docx
    com.apple.FinderInfo           32
    com.apple.lastuseddate#PS          16
    com.apple.quarantine           29

Best Answer

In Terminal, if the actual filename is ~$file.docx then use, rm '~$file.docx', or whatever the actual file name is. If it's ~file.docx, use: rm '~$file.docx'

The above rm commands assume you are in the directory containing the target file, otherwise use its fully qualified pathname.

As the file is hidden, you can use either chflags nohidden '<file name>' or SetFile -a v '<file name>', where '<file name>' is the actual name or fully qualified pathname of the target file, to first unhide the file in Terminal and then in Finder right-click and select: Move to Trash