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: Ctrl-x * expands a wildcard on the bash line before you run it

Bash
~/tips/tip-bash-ctrl-x-star-glob-expand

rm old-*.log

See exactly which files a glob matches, and edit the list, before pressing Enter.

Before you run rm with a wildcard, I think it is worth knowing exactly which files it will hit. Bash can replace the pattern on the line with the real file names.

Type the command with the glob, put the cursor right after the pattern and press Ctrl-x followed by *:

$ rm old-*.log
# press Ctrl-x *
$ rm old-2025-01.log old-2025-02.log old-2025-03.log

The line now holds the actual names. You can remove one you want to keep, add another, or press Ctrl-c if the list is not what you expected. Nothing has run yet.

Ctrl-x g is the read-only version: it lists the matches below the line without changing it, which is enough when you only want a peek.

Very large matches fill the line with hundreds of names, which is a hint by itself to use find instead. It expands only the word before the cursor, so for a command with two globs, do each one.

Further reading: Bash manual: Letting Readline Type For You

More Bash tips echo {01..10} cmd > file 2>&1 export HISTIGNORE='ls*:pwd:cd*' #rsync -av --delete /srv/media/ /mnt/backup/media/ APP_HOST=example.com All Bash tips (52) All topics

Link