#!/usr/bin/env zsh # ── locate.zsh : instant filename search from a prebuilt index (plocate) ───── # find/fd walk the disk live; locate queries a database built ahead of time, so # it answers "where is anything named X?" across the WHOLE system in millisecs. # Trade-off: the DB is a snapshot — brand-new files won't show until updatedb. # On this box `locate` is plocate; DB at /var/lib/plocate/plocate.db. # # loc search the index loci case-insensitive # locb match the BASENAME only locc just count how many # locu refresh the DB (sudo updatedb) — run after adding files # locate-cheat this card if command -v locate >/dev/null 2>&1; then alias loc='locate' alias lo='locate' alias loci='locate -i' # case-insensitive alias locc='locate -c' # count only alias locb='locate -b' # match against basename alias loce='locate -e' # only paths that STILL exist alias locu='sudo updatedb' # rebuild the index fi loccheat() { print -P "" print -P "%F{#9ccfd8}▰▰▶ LOCATE CHEAT SHEET%f %F{#908caa}instant filename search (plocate)%f" print -P "%F{#908caa}──────────────────────────────────────────────────────────────%f" print -P "%F{#f6c177} idea%f queries a prebuilt INDEX — whole-system, instant, but a snapshot" print -P "%F{#f6c177} everyday%f" print -P " %F{#e0def4}locate sshd_config%f every path containing that string" print -P " %F{#e0def4}loci readme%f case-insensitive" print -P " %F{#e0def4}locate -b '\\\\wordlist'%f exact BASENAME (\\\\ = match whole name)" print -P " %F{#e0def4}locate -c '*.pcap'%f just COUNT the hits" print -P " %F{#e0def4}locate -e secret.txt%f only paths that still exist on disk" print -P " %F{#e0def4}locate -l 20 conf%f stop after 20 results" print -P "%F{#f6c177} patterns%f" print -P " %F{#e0def4}locate '*/etc/*.conf'%f glob (auto-wrapped in * unless you glob)" print -P " %F{#e0def4}locate --regex '\\\\.py$'%f full regex match" print -P "%F{#f6c177} keep it fresh %F{#908caa}(the one gotcha)%f" print -P " %F{#e0def4}sudo updatedb%f or %F{#e0def4}locu%f rebuild the DB after adding files" print -P " %F{#908caa}stale results = you haven't updatedb'd since the file appeared%f" print -P "%F{#f6c177} locate vs find/fd%f" print -P " %F{#e0def4}locate%f system-wide, instant, cached (may be stale)" print -P " %F{#e0def4}fd name .%f live, current dir, respects .gitignore, always current" print -P "%F{#908caa}──────────────────────────────────────────────────────────────%f" print -P "%F{#908caa} DB: %f%F{#e0def4}/var/lib/plocate/plocate.db%f%F{#908caa} · not found? %f%F{#e0def4}sudo updatedb%f%F{#908caa} once to build it%f" } alias locate-cheat='loccheat' alias lochelp='loccheat'