问题
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