The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Find and Remove bad files with shell

Discussion in 'General Discussion' started by paulmulder, Feb 15, 2007.

  1. paulmulder

    paulmulder Member

    Joined:
    Jun 5, 2004
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    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. Spiral

    Spiral BANNED

    Joined:
    Jun 24, 2005
    Messages:
    2,023
    Likes Received:
    7
    Trophy Points:
    0
    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. paulmulder

    paulmulder Member

    Joined:
    Jun 5, 2004
    Messages:
    7
    Likes Received:
    0
    Trophy Points:
    1
    Yes

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

    Thank you!
     
Loading...

Share This Page