If you've been using the Unix/Linux command line for any length of time, you're certainly familiar with time-saving techniques like tab completion and reverse-i-search. Chances are you use these darling keystroke-savers daily.

These features of course make a ton of sense—why should *nix force you through the unbearable tedium of typing a full directory name when the computer is perfectly capable of guessing what you're about to type?

Well, today I'm about to (hopefully) blow your mind with another time-saver of whose existence you might not have been aware. It's called brace expansion.

The problem

Tell me if this looks familiar: you want to make just a minor change to a filename, but since the file is so deeply nested in your directory structure, you have to type SO...MUCH...STUFF just to slap a few characters onto the beginning:

mv app/views/appointments/_services.html.erb app/views/appointments/_service_list.html.erb

Totally un-DRY.

The solution

Thanks to brace expansion, you can type only the unique parts. The following command is functionally equivalent to the first one:

mv app/views/appointments/{_services.html.erb,_service_list.html.erb}

Isn't that wonderful? Go ahead and pop open a console right now to try it out. It's an absolute delight.

It works everywhere

The utility of brace expansion is not limited to the mv command. You can use it withcp or anywhere else you think makes sense. If you're a Vim user, you can try something like this, which will open three files in tabs:

vi -p app/views/appointments/{new.html.erb,edit.html.erb,show.html.erb}

In addition to useful things you can do silly things: touch file{1..5}.html Why would you ever want to do that? I don't know, but you can!

That's it. Hopefully that seems useful. You'll thank me when you're 90 years old and thinking back to all the wonderful things you did with those extra 12 minutes you saved over the years, courtesy of brace expansion.

Get the Honeybadger newsletter

Each month we share news, best practices, and stories from the DevOps & monitoring community—exclusively for developers like you.
    author photo
    Starr Horne

    Starr Horne is a Rubyist and Chief JavaScripter at Honeybadger.io. When she's not neck-deep in other people's bugs, she enjoys making furniture with traditional hand-tools, reading history and brewing beer in her garage in Seattle.

    More articles by Starr Horne
    An advertisement for Honeybadger that reads 'Turn your logs into events.'

    "Splunk-like querying without having to sell my kidneys? nice"

    That’s a direct quote from someone who just saw Honeybadger Insights. It’s a bit like Papertrail or DataDog—but with just the good parts and a reasonable price tag.

    Best of all, Insights logging is available on our free tier as part of a comprehensive monitoring suite including error tracking, uptime monitoring, status pages, and more.

    Start logging for FREE
    Simple 5-minute setup — No credit card required