Locate specific folders

locate

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

Best Answer

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.

Related Question