Unix Trick: Brace Expansion

Last week I blogged about my favorite Unix trick. Today I’m going to look at another – probably my second favorite Unix trick.

Brace expansion is a mechanism by which arbitrary strings may be generated. It allows you to replace commands like these:

cp long_and_complex_file_name long_and_complex_file_name.backup

with this:

cp long_and_complex_file_name{,.backup}

It’s very useful for renaming files, especially when you made a typo in a filename.

Happy coding.