sed permission denied when overwriting file

前端 未结 9 548
我在风中等你
我在风中等你 2021-01-11 12:07

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

$ sed -i \'s@@

        
9条回答
  •  时光说笑
    2021-01-11 12:52

    Seems like you have a permission issue on the /tmp dir. (as discussed bellow, you run command in phpshell, so TMP dir can be setted elsewhere than /tmp)

    It should looks like :

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

    explanations

    When invoking sed with -i flag, sed create a temporary file in /tmp dir.


    Proof with 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 +++
    

提交回复
热议问题