← Back to list

The Bracket Trick That Lets You Type Two File Names in Half the Keystrokes

Curly braces that quietly do the repetitive part of typing for you

Sabit in Bash_DevOps_AI · 2026-06-24 11:01 · 0 claps · 2.8 min read paywalled
#programming #coding #devops #linux #productivity
Open on Medium ↗
Wiki topics: 💻 · Programming ☁️ · DevOps & Cloud 🔧 · Data Engineering 🔓 · Open Source ⏱️ · Productivity

The Bracket Trick That Lets You Type Two File Names in Half the Keystrokes

Curly braces that quietly do the repetitive part of typing for you

Photo by Sufyan on Unsplash

Photo by Sufyan on Unsplash

Some file operations involve typing the same file name twice in a row.

They only have one small difference at the end. For instance, when you’re renaming a file or backing one up before you edit it. Or even creating two versions of the same config.

Every time, you type out the full name once, then type almost the exact same thing again right after it.

There’s a shortcut for exactly this pattern, and it lives inside a pair of curly braces.

The trick itself

{}

Curly braces let you write the part of a file name that’s shared once, then list the parts that differ inside the braces, separated by a comma.

Your terminal expands that into both full names automatically, before the command ever runs.

Here’s what that looks like with a real example. Say you have a file called notes.txt, and you want to rename it to notes.bak instead.

Normally, you’d type the command like this.

mv notes.txt notes.bak

With curly braces, you only type the shared part, notes, once.

mv notes.{txt,bak}

Run that, and your terminal expands it into the exact same command as above, notes.txt and notes.bak, before mv ever runs. The result is identical. The typing is shorter, and the shared part of the name only has to be typed once instead of twice.

Note there’s no space between “txt,bak” inside the curly braces.

A second real example, with cp

This works the same way for copying a file to create a backup before editing it. Say you have a file called config.json, and you want a config.json.backup copy of it before making changes.

Typed out in full, that’s two separate file names.

cp config.json config.json.backup

With curly braces, you type the shared part once.

cp config.{json,json.backup}

Same result. Two files, config.json left untouched and a new config.json.backup created alongside it. Less typing, and less room for a typo to sneak into the part of the name that's supposed to be identical in both places.

Why this matters beyond just saving keystrokes

The real value isn’t only speed. It’s accuracy.

When you type a long file name out twice, there’s a real chance of a small typo creeping into the second copy, a missed letter, a different case, or something subtle enough that you don’t notice until later.

With curly braces, the shared part exists exactly once in what you typed. There’s nothing to retype. This means nothing to accidentally retype wrong.

It works with more than two options

You’re not limited to two items inside the braces. List as many as you need, each separated by a comma.

mkdir project-{frontend,backend,docs}

This creates three folders in one line, project-frontend, project-backend, and project-docs, sharing the same base name without typing project- three separate times.

Where this trick saves the most typing

A few situations where curly braces earn their keep the most:

  • Creating a backup of a file before editing it, where the original name and the backup name share most of their characters
  • Setting up several similarly named folders at once, like environments or project sections
  • Renaming a file with a long, specific name where only a small part is actually changing

That last one is where the time savings really add up. The longer the shared part of the name, the more typing the curly braces save you.

Why this stays unfamiliar to most people

Curly brace expansion looks slightly unusual the first time you see it. This is probably why it doesn’t show up in most beginner introductions to the terminal.

It looks like a small syntax trick rather than something useful, so it tends to get skipped over in favor of more obviously important commands.

Once you’ve used it a handful of times, retyping a long shared file name twice starts to feel tedious. The braces quietly take over that part of the job, and you’re left typing only the part that’s actually different.


메타데이터
post_id
01b55f4570a7
slug
the-bracket-trick-that-lets-you-type-two-file-names-in-half-the-keystrokes-01b55f4570a7
url
https://medium.com/my-lifes-mirrow/the-bracket-trick-that-lets-you-type-two-file-names-in-half-the-keystrokes-01b55f4570a7
canonical_url
https://medium.com/my-lifes-mirrow/the-bracket-trick-that-lets-you-type-two-file-names-in-half-the-keystrokes-01b55f4570a7
author_url
https://medium.com/@tibas
status
ok
fetched_at
2026-06-27 18:37:17