覆盖文件时,sed权限被拒绝 [英] sed permission denied when overwriting file

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

问题描述

我正在尝试使用sed覆盖我的index.php文件,但出现错误:

I am trying to use sed to overwrite my index.php file, but I am getting an error:

$ sed -i 's@<head>@<head><script type="text/javascript" src="new.js"></script>@' index.php
sed: couldn't open temporary file ./sedmZNx8T: Permission denied

有人知道如何解决此问题吗?

Does anyone know how to fix this?

推荐答案

在这里真的没有很好的答案.抱歉,如果线程已死,它会在Google搜索中出现,并且没有任何答案.尽管altendky的答案与我的答案有点相似...有一种解决方法...找到一个可写的世界目录,例如/tmp

Really no great answers here. Sorry if thread is dead, it came up in google searches and nothing really answered the question. Although altendky's answer is sort of the same as mine... There IS a workaround...find a world writable directory, say /tmp

cp /etc/file_to_mod /tmp
sed -i -e 's/foo/bar/g' /tmp/file_to_mod
cat /tmp/file_to_mod >/etc_file_to_mod

希望有帮助!

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

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