sed script - permission denied on temp file

*爱你&永不变心* 提交于 2019-12-08 07:32:35

问题


I just used a combination of find and sed to replace strings in files of a directory.

find . -type f -exec sed -i 's,foo,bar,g' {} +

It got the job done. After that I logged off the server (connected via SSH), and then remembered, that I need to run the command again. So I fired the same command with slightly modified find/replace strings, but it did not work anymore giving the following error:

sed: couldn't open temporary file ./sedPFq4Ck: Permission denied

What is wrong now?

FWIW: the file name of the mentioned temporary file changes after each new try.


回答1:


While editing a file in place, sed creates a temporary file, saves the result and then finally mv the original file with the temporary one.

The problem is that you don't have write permission in the directory where sed is trying to create the temp file.

As the file is ./sedPFq4Ck, check the permission of the directory where you are running the find command.



来源:https://stackoverflow.com/questions/36404475/sed-script-permission-denied-on-temp-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!