having this command:

$ find / -path /home/oldroot -prune -o -name config.yml -exec sed -i'' '/(swipe)|(pinch)/s/[0-9].*/1/' {} \+

won't edit:

couldn't open temporary file /home/shepherd/.config/fusuma/sedSQVSZd: Permission denied

You can say, it does not work because of sudo. But it does not even work with sudo, the point is the -i flag here. find found file /fusuma/config.yml, but -i change it into /fusuma/sedSQVSZd as sideeffect of in-place edditing. So is there a way to persist filenames with sed?

  • 2
    The issue is in creating the temporary file that sed writes the result of the edits into before replacing the original file (this is how "in-place" editing works). The user running sed does not have permission to create the temporary file in that location. Can you show the permissions and ownerships on /home/shepherd/.config/fusuma, /home/shepherd/.config, /home/shepherd and /home and let us know what user is executing that command? – Kusalananda May 16 '20 at 23:06
  • all of them are own by me, except of /home/, which is as usual owned by root. The command is run by sudo privileges – Herdsman May 16 '20 at 23:25
  • but I am not sure these information are needed for clarification of sed command – Herdsman May 16 '20 at 23:34
  • 1
    The issue is not changing the name of the temporary file to replace the original. The issue is creating the temporary file in the first place. – Kusalananda May 17 '20 at 11:16
  • 1
    If you think that it's the pipe causing problem, did you try running that sed command without the pipe on the file directly? sed -i'' '/(swipe)|(pinch)/s/[0-9].*/1/' /home/shepherd/.config/fusuma/config.yml – Kusalananda May 17 '20 at 16:23

Your Answer

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

Browse other questions tagged or ask your own question.