LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-17-2010, 04:53 PM   #1
marspl
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Rep: Reputation: 0
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,

Last edited by marspl; 04-19-2010 at 11:29 AM.
 
Old 04-17-2010, 05:36 PM   #2
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 97
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"' {} {} \;

Last edited by troop; 04-17-2010 at 05:47 PM.
 
1 members found this post helpful.
Old 04-17-2010, 05:54 PM   #3
marspl
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
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

Last edited by marspl; 04-17-2010 at 07:18 PM.
 
Old 04-18-2010, 02:28 AM   #4
troop
Member
 
Registered: Feb 2010
Distribution: gentoo, arch, fedora, freebsd
Posts: 379

Rep: Reputation: 97
Quote:
Originally Posted by marspl View Post
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 View Post
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 View Post
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 {} \;
 
1 members found this post helpful.
Old 04-18-2010, 09:07 AM   #5
marspl
LQ Newbie
 
Registered: Apr 2010
Posts: 3

Original Poster
Rep: Reputation: 0
Thank you very much u helped me alot
 
Old 04-18-2010, 10:16 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,799

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


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Cannot rename or delete files Josho Linux - Newbie 3 04-07-2009 03:47 PM
Samba on RHEL4: Windows users unable to rename or delete files seanys Linux - Software 1 02-13-2009 03:41 AM
To rename files in a directory should I use Bash script or a Perl Script ? jamtech Programming 7 01-23-2008 12:25 AM
Script on linux to delete certain files ForumKid Linux - General 2 06-22-2002 02:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration