brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: rg -g includes or excludes files by pattern

CLI
~/tips/tip-ripgrep-glob-filter

rg 'apiKey' -g '!*.min.js' -g '!package-lock.json'

Limit ripgrep to some file types or skip noisy files with a glob.

Searching a whole project and getting hits from minified bundles, lock files and logs is annoying. ripgrep can filter by file name on the spot.

Use -g (long form --glob) with a pattern:

rg 'TODO' -g '*.py'
rg 'apiKey' -g '!*.min.js' -g '!package-lock.json'

A plain pattern limits the search to matching files. A pattern that starts with ! excludes them. You can repeat the flag as often as you like, and when globs overlap, the later one wins. That makes it easy to say “everything except these two files”.

Quote the pattern so your shell does not expand the star itself. If you only want a language and not a custom pattern, rg -t py uses a built-in file type, and rg --type-list shows all of them.

A caveat: globs work on top of the usual ignore rules. A file that .gitignore hides stays hidden even if your glob matches it, unless you also add --no-ignore.

One more detail: --iglob works like -g but ignores case, and rg --files -g '*.md' only lists the matching file names without searching inside them, which is a quick way to test a glob before you rely on it.

Further reading: ripgrep user guide, manual filtering

Going deeper: Run degoog on Unraid as your own search page, compared with SearXNG and 4get

More CLI tips printf 'GET /\r\n' | hexdump -C hexdump -C -s 512 -n 64 disk.img wget --limit-rate=2m https://example.com/big-file.iso wget --spider https://example.com/file.zip yt-dlp --download-archive archive.txt "https://www.youtube.com/playlist?list=PLAYLIST_ID" All CLI tips (46) All topics

Link