permission denied when sed in place edit in mingw

后端 未结 4 1876
不思量自难忘°
不思量自难忘° 2021-02-06 22:19

I\'m using mingw.

  $ sed -i \"s/a/b/\" test.txt
  sed: preserving permissions for `./sed003480\': Permission denied

I can touch/rm files in cu

相关标签:
4条回答
  • 2021-02-06 22:36

    TL;DR: Used sudo


    In my case, I was running a bash script running on Windows Subsystem for Linux (WSL) as follows:

    ./generate.sh
    

    The script created a bunch of files however, for reasons unknown, sed was denied permission to modify the permissions on these files for some reason:

    The actual sed command was used to perform a search-replace that looked a bit like this:

    grep -rl $PATTERN $PUBLIC_API_FOLDER/ \
        | xargs sed -i 's/$PATTERN/$REPLACE/g'
    

    As you can see, despite not having elevated priviledges at any point, I nevertheless was unable to modify the files the script created:

    sed: preserving permissions for ‘public_api/models/sedt0qk4D’: Operation not permitted
    sed: preserving permissions for ‘public_api/models/sedOxoc1O’: Operation not permitted
    sed: cannot rename public_api/models/sedOxoc1O: Permission denied
    sed: preserving permissions for ‘public_api/controllers/sedx5BafW’: Operation not permitted
    sed: preserving permissions for ‘public_api/models/sedVkdqzc’: Operation not permitted
    sed: preserving permissions for ‘public_api/models/sedLvyS3s’: Operation not permitted
    sed: cannot rename public_api/models/sedLvyS3s: Permission denied
    sed: preserving permissions for ‘public_api/controllers/sedE7GSe8’: Operation not permitted
    sed: cannot rename public_api/controllers/sedE7GSe8: Permission denied
    sed: preserving permissions for ‘public_api/controllers/sednHZBQf’: Operation not permitted
    sed: cannot rename public_api/controllers/sednHZBQf: Permission denied
    

    The solution in my case was to simply run the script with sudo.

    sudo ./generate.sh
    
    0 讨论(0)
  • 2021-02-06 22:48

    On Windows 10 WSL i got similar issue. The issue was caused by VS code being open and apparently using the file. Closing VS code solved my issue.

    0 讨论(0)
  • 2021-02-06 22:50

    It's caused by Windows security settings.

    Open the folder's Properties settings from the context menu. In the Security tab, click Edit, press Add... in the pop-up window and add your user to the list, check Full Control in the Allow column. Press OK twice to apply the changes.

    0 讨论(0)
  • 2021-02-06 23:00

    For me, folder was read only. unchecking readonly option fix my problem. Thanks to Zenadix commment

    0 讨论(0)
提交回复
热议问题