Brace expansion to match multiple files in Bash

Bash has handy brace expansion powers that I’ve belatedly discovered.

$ echo I love hippo{griffs,potamuses,dromes}
I love hippogriffs hippopotamuses hippodromes

For example, you can quickly diff a file with and without a suffix:

$ echo diff .env{,.example}
diff .env .env.example

Or tail multiple log files:

$ echo tail -f /var/log/{messages,secure}
tail -f /var/log/messages /var/log/secure

Bash brace expansion can do other things too, such as specify a range with a .. operator.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.