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.

Published by

Leons Petrazickis

I'm a full-stack developer at IBM Digital Business Group. I do Ruby, Node, Python, Hadoop, Spark, as well as web scale devops with Docker and Terraform. My opinions are my own.