Sitemap
Press enter or click to view image in full size

Member-only story

The Fastest Way to Back Up a File in Bash (You’re Probably Not Using It)

2 min readDec 15, 2025

When working in the terminal, backing up a file before editing it is a habit that saves time, nerves, and sometimes entire systems. There’s a Bash trick that makes this almost effortless:

cp filename{,.bak}

How It Works

This command relies on brace expansion, a shell feature that generates multiple strings from a single pattern.

filename{,.bak}

expands to:

filename filename.bak

So Bash actually executes:

cp filename filename.bak

You type the filename once, and Bash handles the rest.

Why This Is Better Than the “Normal” Way

Most people write:

cp filename filename.bak

That works — but brace expansion has advantages:

  • Faster typing
  • Fewer mistakes, especially with long filenames
  • Cleaner commands
  • Easier to scan in scripts and terminal history

Once you get used to it, going back feels slow.

Real-World Examples

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web
Already have an account? Sign in

Konstantinos Patronas

Written by Konstantinos Patronas

DevOps engineer, loves Linux, Python, cats and Rock music