I'm getting mv: cannot move, Permission denied error, but before claiming this is a dupe, please see what I've tried first:

First of all, it has nothing to do with file or directory mode:

$ mv -f .emacs.d .emacs.d.old
mv: cannot move '.emacs.d' to '.emacs.d.old': Permission denied

$ ls -Al . | grep emacs
drwx------ 1 me me 4096 2021-06-11 23:04 .emacs.d

ls -ld .
drwxr-xr-x 1 me me 4096 2021-06-12 00:17 .

$ sudo mv -f .emacs.d .emacs.d.old
mv: cannot move '.emacs.d' to '.emacs.d.old': Permission denied

$ mv -f .emacs.d ./.emacs.d.old
mv: cannot move '.emacs.d' to './.emacs.d.old': Permission denied

$ df .
Filesystem     1K-blocks      Used Available Use% Mounted on
rootfs         307276796 200040828 107235968  66% /

Second, I tried with every file-open checking tools that I know:

$ jobs | wc
      0       0       0

$ lsof | grep .emacs.d | wc 
      0       0       0

$ fuser .emacs.d | wc
      0       0       0

and I've tried to close whatever that might or might-not related to the .emacs.d directory, including closing vs code that has nothing to do with the .emacs.d directory.

Full disclosure: I am using Windows Subsystem for Linux, but I don't think I have the directory open in any other bash instances. Moreover, as seen in first output, my home dir is within WSL, not under any windows folder (i.e., should have nothing to do with any Windows programs).

I have ran out of ideas what could possibly be holding me back to rename this newly created directory.

  • could you try running mv .emacs.d ./.emacs.d.old ? Looks like this is a bug in WSL, fixed in WSL2, but not completely it seems. It's happening because WSL is pinning all the open files. Another solution was to cp to target and rm the old one. github.com/microsoft/WSL/issues/3738 Jun 12 at 6:06
  • no mv -f .emacs.d ./.emacs.d.old does not work either, see my amended OP, but thanks to your link, to my greatest surprised, "cp to target and rm the old one" just works! So this is definitely a bug in WSL. I can accept that as the answer @BarathVutukuri. thx again.
    – xpt
    Jun 12 at 13:01
  • What about mv .emacs.d emacs.e (no leading dot, no double dot extension)? If that works what about mv emacs.e emacs.d.old and then mv emacs.d.old .emacs.d.old?
    – roaima
    Jun 12 at 14:45

This is a bug in older WSL implementation which keeps pinning all the opened files but forgets to track them when they're closed. This is fixed in most recent versions of WSL and WSL2.

As a temporary hack, one can cp to target and rm the old source

Please refer to the GitHub issues for WSL Project

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.