Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 3 of 3
  1. #1
    Member
    Join Date
    Jun 2004
    Posts
    7

    Default Find and Remove bad files with shell

    I want to try and run a command which will go through all files of the server and remove anything which contains a certain word (after I determine the name of a bad script).

    I first tried:

    locate verybadscript

    This produced an extremely long list of everywhere the file was contained.

    I then ran

    rm -rf /directorywhere the script lives (in one example, where the script was the only thing in that directory).

    When I went to the directory it was indeed gone, but running the locate command again still listed the same directory again and this causes a lot of confusion and provides no clarity.

    I then found the following command

    find / \( -name verybadscript -o -name '*.verybadscript' \) -atime +7 -exec rm {} \;

    This works well. When i then run locate verubadscript it shows that it has been deleted properly in most accounts, with the exception of files that have been added or used in the last 7 days.

    I then tried adjusting this to

    find / \( -name verybadscript -o -name '*.verybadscript' \) exec rm {} \;

    which further removes a lot of files except for those added that day.

    My intention, once I have this adjusted further, is to create a cron which will automatically remove any bad script once or numerous times a day.

    My question is: How can then above command be manipulated further so that every files called 'verybadscript' is deleted, even if it has been used or added in the last 10 minutes?

    I would have thought that removing -atime +7 - would result in all files being deleted regardless of the time they have spent on the server.

    Or else... if anyone has any other ideas, I'd be very grateful if you could provide some advise.

  2. #2
    BANNED
    Join Date
    Jun 2005
    Location
    Wild Wild West
    Posts
    2,025

    Default

    The "locate" command doesn't look at your actual hard drive
    but rather instead a database containing the list of files on
    your hard drive.

    If you add or delete files since the last time the "locate"
    database was updated then the locate command will still
    show the old information.

    To update "locate", type the following in your unix shell:

    updatedb

    (Could take a while to run based on how many files you have)

  3. #3
    Member
    Join Date
    Jun 2004
    Posts
    7

    Default Yes

    I ran updatedb and when I ran the locate command it indeed showed that every had been cleaned up.

    Thank you!

Similar Threads & Tags
Similar threads

  1. Cannot remove bad name user-defined MIME type from cpanel
    By wessam in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 02-09-2009, 10:47 AM
  2. shell script: remove everything behind .'s
    By laborspy in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 04-09-2004, 08:57 AM
  3. Bad CSV Files
    By dynasyn in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 10-21-2003, 10:57 AM
  4. Need to find and remove hidden BNC
    By isnoop in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 09-19-2003, 04:09 AM
  5. remove POP account doesn't remove all files
    By spaceman in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 09-18-2003, 08:05 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube