gpt4 book ai didi

sed script - permission denied on temp file(SED脚本-对临时文件的权限被拒绝)

转载 作者:bug小助手 更新时间:2023-10-24 23:21:53 27 4
gpt4 key购买 nike



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:每次新尝试后,上述临时文件的文件名都会更改。


更多回答
优秀答案推荐

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.

在就地编辑文件时,sed创建一个临时文件,保存结果,然后最后使用临时文件对原始文件进行MV。



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

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



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

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


更多回答

@beta Thats an ambiguous question, check the permission of the directory, you don't have write permission in it..perhaps in the first time, you ran it as different user who has permission..

@beta这是一个模棱两可的问题,请检查目录的权限,您在其中没有写入权限。也许在第一次,您是以其他有权限的用户身份运行它的。

okay, sorry. my admin changed the permissions between my two attempts. i wasn't aware of this.

好的,对不起。我的管理员在我两次尝试之间更改了权限。我没有意识到这一点。

I have a similar sort of a problem where I run sed only but with sudo, and I get a similar message. Any idea why I am not able to do it despite sudo

我遇到了类似的问题,我只运行sed,但使用sudo,我得到了类似的消息。你知道为什么我不能做到这一点吗,尽管Sudo

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com