3

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??

2
  • 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, 2015 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, 2015 at 18:29

2 Answers 2

6

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.

5
  • Thanks man.. it worked for me. Will accept in 6 minutes/
    – mysterious
    Mar 17, 2015 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, 2015 at 19:02
  • @mdpc: Thanks..added the conf file info too..
    – heemayl
    Mar 17, 2015 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, 2015 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, 2015 at 21:52
1

Always better late than never. fd is the new find.

Options:

  • H - search hidden files and folders
  • I - do not respect ignore files
  • t - type of file to search for (d == directory)

Usage:

fd -HI -t d 'wordpress-seo$'

As for speed, you can find benchmarks here, but strictly speaking fd is exponentially faster than find.

Fedora Install:

sudo dnf install fd-find

Debian Install:

sudo apt-get install fd-find

Other installation methods can be found at the github

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .