One feature of Bash that would have saved me a lot of keystrokes if I’d known about it sooner is brace expansion.
Here’s the most common way I use it. Instead of typing out both full filenames when renaming a file, as you would like this:
You can instead use brace expansion to specify what to change:
It’s not even necessary to include a value on both sides of the comma, so if you’re appending text to a filename it would look like this:
mv, the values are old and new but you can also use brace expansion with commands like mkdir or touch. Say you want to set up a new workspace for programming Go, you can do this in a single command like this:
One last thing. Brace expansion also supports iterating, and while I can’t imagine a good use for it, here’s how it’s done:
By prefixing the first value with an extra zero, Bash knows to pad all of the numbers with zeros to match the width of the end value.
The iteration can also accept a value to describe the increment used, like so:
But really, the only place I find myself using brace expansion frequently is for
mv operations, and it’s fantastic just for that.