Skip to main content

Basic Patterns

Substring Search (Default)

locate performs a substring search by default. If your query appears anywhere in the full file path, the file is returned.

# Finds any path containing "nginx"
locate nginx
# /etc/nginx/
# /etc/nginx/nginx.conf
# /usr/sbin/nginx
# /var/log/nginx/access.log

Searching for Exact Filenames

Because the search targets the full path, an overly broad query returns too many results. Narrow it:

# Too broad — returns /etc/nginx/, /usr/share/nginx/ ...
locate nginx

# More targeted — only "nginx.conf" anywhere in the path
locate nginx.conf

# Even more targeted — full path anchor
locate /etc/nginx/nginx.conf

Case Insensitivity (-i)

By default locate is case-sensitive:

locate Nginx # only paths with capital N
locate -i nginx # matches nginx, Nginx, NGINX
locate -i "readme" # matches README.md, readme.txt, Readme.MD

Limiting Results (-n)

# Show only the first 10 results
locate -n 10 "*.log"

# Combined with counting for a quick survey
locate -c nginx # just the count

Multiple Patterns (AND behavior)

Provide multiple arguments — locate returns paths that match all of them:

# Path must contain BOTH "nginx" AND "conf"
locate nginx conf

# Both "python" and "site-packages"
locate python site-packages