sed permission denied when overwriting file

前端 未结 9 581
我在风中等你
我在风中等你 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 13:02

    Given that you do not have write access to the directory where index.php is stored, then generally you would not have access to index.php...? Assuming this is a 'non-standard' case and you do have write access, sed -i is trying to create a temp file in the same directory as index.php (just checked and it is the same directory, not the CWD). Run sed without -i and end the line with something like > ~/sed.out to write the result into a file in your home directory. Then do what you will with that file.

    sed 's@@@' index.php > ~/sed.out
    

    Be aware that you while you can cp ~/sed.out index.php you can not mv ~/sed.out index.php. It would seem that cp will put the contents into index.php (not modifying the directory you do not have write permissions to) while mv tries to change the directory (that you don't have write permissions to).

提交回复
热议问题