sed脚本-临时文件的权限被拒绝 [英] sed script - permission denied on temp file

查看:2731
本文介绍了sed脚本-临时文件的权限被拒绝的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

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

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

现在怎么了?

FWIW:每次尝试后,上述临时文件的文件名都会更改.

解决方案

在适当位置编辑文件时,sed创建一个临时文件,保存结果,然后最终将mv与该临时文件保存在一起.mv /p>

问题是您在sed试图创建临时文件的目录中没有写许可权.

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

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.

解决方案

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.

这篇关于sed脚本-临时文件的权限被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆