Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 248
glarkou Avatar asked Jul 21 '26 21:07

glarkou


1 Answers

I'm assuming your using Ubuntu due to sudo?

Firstly make sure you are in the same directory as the file you are trying to delete, do this with:

print(getcwd());

Secondly try changing the owner of file your are trying to delete to www-data (or apache depending on your server) and then see if you can delete the file from the php script.

If this works then the problem you have is permission related.

There are a number of ways to solve this problem.

  1. Make sure the files your are deleting are owned by the web server process (most secure).
  2. Give the files 777 permissions so any user can delete them.
  3. Add the web server user to sudoers (/etc/sudoers) (least secure)
like image 154
Kinetic Avatar answered Jul 23 '26 11:07

Kinetic