Permission denied when trying to 'mv' a directory

20,861

I think that a service or a program of windows is perhaps using or accessing the same file , i used to have the same problem when i first installed the linux subsystem on windows 10.

Share:
20,861

Related videos on Youtube

Admin
Author by

Admin

Updated on September 18, 2022

Comments

  • Admin
    Admin over 1 year

    Situation:

    • I am using Bash with Linux subsystem for Windows(10); I am logged in as root.
    • All folders and files in my current directory have rwxrwxrwx, and the same is true for descendant files and folders.
    • There is no system file in my current directory nor in the descendants.
    • None of folders is synchronized with git.

    Problem:

    • I cannot change the name of one particular directory. However I can do this for every single other directory or file - whether in the current directory, or inside the un-mv-able directory in question.

    I can copy a whole directory to another one and then freely change its name, or I can copy its contents to the folder with the desired name, and those solutions are acceptable, but using just mv would be easier. For the sake of knowledge - as a bash and Linux beginner - I really would like to understand the problem.


    Additional info as requested
    root@MARVIN:/mnt/h/testing# mv test1.pl otherName
    mv: cannot move ‘test1.pl’ to ‘otherName’: Permission denied
    
    root@MARVIN:/mnt/h/testing# lsattr test1.pl
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/css
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/fonts
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index.html
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index2.html
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index3.html
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index4.html
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/index5.html
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/js
    lsattr: Inappropriate ioctl for device While reading flags on test1.pl/notes.txt
    

    Given various operations I was doing on partition directory resides on, I guess it is not read-only, but for the record:

    root@MARVIN:/mnt/h/testing# mount
    rootfs on / type rootfs (rw,relatime)
    sysfs on /sys type sysfs (rw,nosuid,nodev,noexec,relatime)
    proc on /proc type proc (rw,nosuid,nodev,noexec,relatime)
    devpts on /dev/pts type devpts (rw,nosuid,noexec,relatime,gid=5,mode=620,ptmxmode=000)
    tmpfs on /run type tmpfs (rw,nosuid,noexec,relatime,size=204320k,mode=755)
    none on /run/lock type tmpfs (rw,nosuid,nodev,noexec,relatime,size=5120k)
    none on /run/shm type tmpfs (rw,nosuid,nodev,relatime)
    none on /run/user type tmpfs (rw,nosuid,nodev,noexec,relatime,size=102400k,mode=755)
    


    Solution

    The directory was in fact blocked by Atom editor (installed on Windows not WSL).

    Details

    enter image description here

    The directory in question is directory A.

    • If one of files Aa, Ab, Ac is opened in the editor, I can mv Dir A.
    • If one of files AAa ... ABc is opened I get Permission denied.
    • If contents of Dir A are visible it Atom project browser, I can mv it.
    • If contents of Dir AA or Dir AB are visible in Atom p. b., I get Permission denied.
    • Admin
      Admin about 7 years
      do lsattr <directory> please and share the output
    • Admin
      Admin about 7 years
      Does your unmovable files is residing in any readonly partition?
    • Admin
      Admin about 7 years
      Question was updated with all requested info.
    • Admin
      Admin about 7 years
      Does otherName already exist (including all variations, capitalized or not)? Have test1.pl or H:\testing recently been modified by an ordinary (non-WSL) Windows program?
    • Admin
      Admin about 7 years
      otherName does not exist; sibling-directories to the directory in question could have their names changed to otherName without a problem. About the modification - AFAIK: no. I may add that test1.pl is directory for the virtual host of Apache, but still, as well are neighbouring directories that could be mv-ed freely.
    • Admin
      Admin about 7 years
      I have inadvertently killed experimental subject. To verify if directory is attached to some Windows service I copied it and tried to remove it - sadly not with Windows "delete" but rm -r. Much to my surprise directory vanished without a single objection. I then renamed the copy of directory to the original name test1.pl and now I obviously can mv it, but further troubleshooting may be difficult. I will report if the problem will come back after next reboot.
    • Admin
      Admin about 7 years
      If this happens again, try renaming it in windows explorer - it might give a more precise error message.
    • Admin
      Admin about 7 years
      @Mark Plotnick I updated my question. I guess your suggestion that Windows program modifies this directory was correct, but - at least for me - it was happening in a hard to notice way.
    • Admin
      Admin over 4 years
  • raphaklaus
    raphaklaus over 3 years
    In my case, I just closed VSCode and it worked.