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: GLOBIGNORE hides backup files from every shell wildcard

Shell
~/tips/tip-shell-globignore

GLOBIGNORE='*.bak:*~'

Keep *.bak or *~ files out of every * you type in that session.

Editors and scripts leave *.bak and *~ files everywhere, and every * drags them along into commands. Bash can leave them out of all globs at once.

GLOBIGNORE holds a colon separated list of patterns. Names that match are dropped from every glob result:

GLOBIGNORE='*.bak:*~'
ls *
grep -l TODO *

Both commands now skip nginx.conf.bak and notes.txt~. The files are still there; typing the name in full still works, only the wildcards stop returning them.

The manual mentions a side effect that is easy to miss: setting GLOBIGNORE to anything also switches on dotglob, so * now matches hidden files like .env too. If you do not want that, add them to the list: GLOBIGNORE='*.bak:*~:.*'.

Clear it with unset GLOBIGNORE, which also turns that hidden-file behaviour off again. Since it changes what every * means, I would not set it in ~/.bashrc; a later rm * that leaves files behind is confusing in its own way. In a script for one task it is neat.

Further reading: Bash manual: Bash Variables (GLOBIGNORE), Bash manual: Filename Expansion

More Shell tips zmv -n '(*).log' '$1.txt' zoxide query -ls project f=$(mktemp --suffix=.json) shopt globskipdots echo $EPOCHSECONDS All Shell tips (78) All topics

Link