2

I want to locate all folders on my server that end with 'wordpress-seo'.

I tried find command but it takes too long.

sudo  find /home/w/s -type d -name 'wordpress-seo'

Now I am trying Locate command but it returns all paths that have wordpress-seo.

a/wp-content/plugins/wordpress-seo
a/wp-content/plugins/wordpress-seo/languages/
...
...

I want to exclude wordpress-seo/* files and folders. I just want folder names. i.e.

a/wp-content/plugins/wordpress-seo
b/wp-content/plugins/wordpress-seo

Tried regex without any luck.

locate -r '/\w+wordpress\-seo/b'
OR
locate '/*/wordpress-seo/'

Any Help??

  • I'm surprised 'find' is too slow. This is just the sort of job it is good at. Can you limit the depth of the search with -maxdepth? – gogoud Mar 17 '15 at 18:13
  • what filesystem? btrfs? can you be sure that locate will work? Seems to me it reads from a system database of system files and not from the real directories... – gogoud Mar 17 '15 at 18:29
5

Try this:

locate -r "wordpress-seo$"

Although i should mention that find offers huge variations of options over locate. You have found locate faster because it just reads from a database /var/lib/mlocate/mlocate.db while find search through files every time, whenever you give it something to search.

locate's database is updated by cron on a daily basis, you can also update the database manually anytime by:

sudo updatedb

This will make the files created after the daily cron update available in the locate database, so you will find those via locate. Also check the configuration file /etc/updatedb to see which filesystems, paths are being excluded.

  • Thanks man.. it worked for me. Will accept in 6 minutes/ – mysterious Mar 17 '15 at 18:17
  • NOTE: You should check the /etc/updatedb.conf to ensure it is catching all the areas that you are interested in. Also, remember that the locate output is only at the point when updatedb was done, whereas find uses what is on the disk NOW. – mdpc Mar 17 '15 at 19:02
  • @mdpc: Thanks..added the conf file info too.. – heemayl Mar 17 '15 at 21:44
  • 1
    I like how you mentioned that locate reads from a database. locate isn't magically faster than find. It does come at a cost albeit one that isn't too high anymore. – SailorCire Mar 17 '15 at 21:47
  • Basically you are substituting a limited find done during an early morning most likely taking the time (cpu, io, wait) rather than doing it NOW and waiting then. Tradeoff is the accuracy of the list ... it might be older than you wish. – mdpc Mar 17 '15 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.