43

I'm using mingw.

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

I can touch/rm files in current dir.

peon
  • 1,833
  • 2
  • 19
  • 21
  • I'm having the same issue. Seems like a duplicate of http://stackoverflow.com/q/12850882/911550 - different platform though. – parvus Jan 17 '13 at 10:51

4 Answers4

45

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.

FRob
  • 3,883
  • 2
  • 27
  • 40
peon
  • 1,833
  • 2
  • 19
  • 21
  • 2
    Perhaps in English Windows it is called "Full Control". – Qwertie Jul 07 '14 at 05:54
  • 1
    @Jacob - I had this too. The fix for me was to use git bash that's comes with https://git-scm.com/download/win instead of mingw that comes with sourcetree. The git one is 64bit whereas sourcetrees was 32 bit, not sure if that is the only difference. – elRobbo Jun 20 '16 at 04:29
  • Using 64 bit Git Bash worked for me as well on Windows 7 – codehearts Apr 09 '18 at 23:45
7

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

Tapash
  • 762
  • 9
  • 7
2

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

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
Eric McLachlan
  • 3,132
  • 2
  • 25
  • 37