+-
linux – 覆盖文件时拒绝sed权限
我试图使用sed覆盖我的index.php文件,但我收到一个错误:

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

有谁知道如何解决这一问题?

最佳答案
好像你在/ tmp目录上有权限问题. (如下所述,您在phpshell中运行命令,因此TMP目录可以在/ tmp之外设置)

它应该看起来像:

$ls -ld /tmp
drwxrwxrwx 333 root root 32768 12 oct.  03:13 /tmp/

说明

当使用-i标志调用sed时,sed在/ tmp目录中创建一个临时文件.

strace证明:

$strace -f -e trace=file sed -i 's/a/z/' /tmp/a
execve("/bin/sed", ["sed", "-i", "s/a/z/", "/tmp/a"], [/* 94 vars */]) = 0
access("/etc/ld.so.preload", R_OK)      = -1 ENOENT (No such file or directory)
open("/etc/ld.so.cache", O_RDONLY|O_CLOEXEC) = 3
(...)
open("/tmp/sedPSBTPG", O_RDWR|O_CREAT|O_EXCL, 0600) = 4
rename("/tmp/sedPSBTPG", "/tmp/a")      = 0
+++ exited with 0 +++
点击查看更多相关文章

转载注明原文:linux – 覆盖文件时拒绝sed权限 - 乐贴网