locate, which & xargs

Faster lookups and bulk actions

locate - instant, but from an index

locate searches a prebuilt database instead of walking the disk, so it's blazing fast - but the DB can be stale.

$ locate nginx.conf      # instant
$ sudo updatedb          # refresh the index

which / type - where's this command?

$ which python3
/usr/bin/python3

xargs - turn output into arguments

Some commands don't read from pipes. xargs bridges the gap by converting piped text into command arguments.

# find files, then grep inside them:
$ find . -name '*.py' | xargs grep -l 'import os'

# safer with weird filenames (null-delimited):
$ find . -name '*.log' -print0 | xargs -0 rm
Tip: find's own -exec runs the command once per file; piping to xargs batches many files into one invocation - much faster for thousands of matches.
Warning: Filenames with spaces break naive pipelines. Use find -print0 | xargs -0 (null-separated) to stay safe.