bash sed 脚本 - 临时文件的权限被拒绝

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36404475/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 14:27:58  来源:igfitidea点击:

sed script - permission denied on temp file

bashsedpermissionspermission-denied

提问by beta

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

我只是使用 find 和 sed 的组合来替换目录文件中的字符串。

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:

它完成了工作。之后,我注销了服务器(通过 SSH 连接),然后记住,我需要再次运行该命令。所以我用稍微修改的查找/替换字符串触发了相同的命令,但它不再起作用,给出以下错误:

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.

FWIW:每次新尝试后,提到的临时文件的文件名都会更改。

回答by heemayl

While editing a file in place, sedcreates a temporary file, saves the result and then finally mvthe original file with the temporary one.

就地编辑文件时,sed创建一个临时文件,保存结果,最后保存临时文件mv的原始文件。

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

问题是您在sed尝试创建临时文件的目录中没有写权限。

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

由于文件是./sedPFq4Ck,请检查您运行find命令的目录的权限。