Skip to content

Instantly share code, notes, and snippets.

@nepsilon
Last active July 12, 2016 06:48
Show Gist options
  • Save nepsilon/9a21e0a21e30ba2b80ec to your computer and use it in GitHub Desktop.
Save nepsilon/9a21e0a21e30ba2b80ec to your computer and use it in GitHub Desktop.
Find your stuff with locate — First published in fullweb.io issue #11

Find your stuff with locate

Following on last week grep tips, let’s see how to use locate to search for files on your Linux machine. The locate command is faster than find because it uses a database, whereas find will scan the file system every time.

locate uses a database, you first need to build it with:

$ sudo updatedb

Search recursively into a folder:

$ locate pattern folder/

If no folder specified search is system-wide, ex:

$ locate "*.py"

# Filter out error msg with -q
# (permission denied, etc)
locate -q "*.py"

Only count pattern occurrences:

$ locate -c pattern

Search is case sensitive use -i to disable it:

$ locate -i "*.hTmL"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment