Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

Delete files using locate database

Discussion in 'General Discussion' started by ManXP, Sep 18, 2010.

  1. ManXP

    ManXP Well-Known Member

    Joined:
    Feb 3, 2005
    Messages:
    62
    Likes Received:
    0
    Trophy Points:
    156
    Hi,

    I want to make a simple script which could locate and delete some files using locate database. That's right, I want script to use LOCATE (not find) command because it's much faster.

    Script should also display files located/deleted. At the moment I have a script like this:


    find /home -name error_log -exec rm -f {} \;
    find /home -name "Thumbs.db" -exec rm -f {} \;

    However, it does not display deleted files, and if I change "find" to "locate", it simply doesn't work. Could anyone provide me a working example of this simple script using locate, please? Google didn't return me what I wanted...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  2. u001b

    u001b Registered

    Joined:
    Aug 26, 2011
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    51
    Locate doesn't have the built-in -exec option like find does, but you can pipe to xargs to complete the task:
    Code:
    locate error_log | xargs rm -f
    locate Thumbs.db | xargs rm -f
    And if filenames/directories contain whitespace:
    Code:
    locate -0 error_log | xargs -0 rm -f
    locate Thumbs.db | xargs -0 rm -f
     
Loading...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice