LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Linux Script to Delete and/or Rename Files (https://www.linuxquestions.org/questions/programming-9/linux-script-to-delete-and-or-rename-files-802589/)

marspl 04-17-2010 03:53 PM

Linux Script to Delete and/or Rename Files
 
We have a problem at work that we are using Word Press And now for security we have to delete install.php in WP-Admin and rename upgrade.php and install_helper.php to *.bak
Im a noob in Script creating (Had a bit practice a couple of years ago but allready forgot T.T) So what i ask that is there a way to make a script

That:
Finds wp-admin(if it exists) folder enters into it and there deletes install.php and renames upgrade.php and install_helper.php to *.bak and the makes the same process again untill theres no wp-admin folders left with these files, We have alot of web pages so manually it would take about a month to find em all (about 3000 pages :/)

Thank you,

troop 04-17-2010 04:36 PM

Code:

find . -type f -wholename '.*wp-admin/install.php' -delete
find . -type f -wholename '.*wp-admin/upgrade.php' -exec mv {} {}.bak \;
find . -type f -wholename '.*wp-admin/install_helper.php' -exec mv {} {}.bak \;

or
Code:

find . -type f -wholename '.*wp-admin/install.php' -delete
find . -type f -wholename '.*wp-admin/upgrade.php' -exec sh -c 'mv -i "${1%php}"php "${1%php}bak"' {} {} \;
find . -type f -wholename '.*wp-admin/install_helper.php' -exec sh -c 'mv -i "${1%php}"php "${1%php}bak"' {} {} \;


marspl 04-17-2010 04:54 PM

Thanks alot, im useless at Linux script creating so u saved my life :)

btw i use it with
#!/bin/bash or something else?

And what would be the command to delete whole folder?

and to change permissions?
find . -type f -wholename '.*wordpress/wp_config.php' -exec chmod {} 644\;


Thank you

troop 04-18-2010 01:28 AM

Quote:

Originally Posted by marspl (Post 3938834)
btw i use it with
#!/bin/bash or something else?

You can use #!/bin/bash or #!/bin/sh. It does not matter.

Quote:

Originally Posted by marspl (Post 3938834)
And what would be the command to delete whole folder?

rm -f dir_name
to delete wordpress folders for example
Code:

find . -type d -name 'wordpress' -exec rm -f {} \;
Quote:

Originally Posted by marspl (Post 3938834)
and to change permissions?
find . -type f -wholename '.*wordpress/wp_config.php' -exec chmod {} 644\;

fixed:
Code:

find . -type f -wholename '.*wordpress/wp_config.php' -exec chmod 644 {} \;

marspl 04-18-2010 08:07 AM

Thank you very much u helped me alot

grail 04-18-2010 09:16 AM

Great to see you have an answer, but please mark as SOLVED so we all know that is the case :)


All times are GMT -5. The time now is 02:35 AM.