Search code examples
phpbashfilesystemsescaping

How to delete a file on Linux using exec


I am trying to delete a previously created file called a\.

I tried to use:

1)

rm -rf a\\

2)

rm -rf a\\/

but both are not working. I tried to login to the terminal but I was unable to delete. I wrote a and then clicked tab and it shows a\\/ but it stills not working. Neither from terminal. I get:

 sudo rm -rf a\\/
 rm: cannot remove `a\\': Operation not permitted

Any suggestions?


Solution

  • You should use exec("rm -rf a\\\\"); in your php code.

    Php uses \\ to escape \ and system uses the same, so you need to escape \ twice