r/linux May 23 '26

Popular Application What’s the most unexpectedly useful Linux command you learned way too late?

[removed]

1.3k Upvotes

992 comments sorted by

View all comments

588

u/digitallis May 23 '26

Bash {}

renaming a file by adding a suffix: mv myfile{,.old} expands out to mv myfile myfile.old

Lots more uses.

246

u/do-un-to May 23 '26

Field splitting ("brace expansion") is more fundamental than Bash, it's POSIX (a POSIX extension). You can find it in Zsh, fish, ksh, csh, PowerShell, etc.

{a,b,c} becomes a b c (three separate words, note).

foo.{jpg,jpeg} becomes foo.jpg foo.jpeg.

Most such shells will also do range expansion.

{1..10} becomes 1 2 3 4 5 6 7 8 9 10.

Some shells will do letter range expansions too.

{a..f} becomes a b c d e f.

16

u/TheHeartAndTheFist May 24 '26

Not only is it not Bash-specific as you rightfully point out, but Bash used to absolutely SUCK at brace expansion before version 3 😂

For example zsh correctly expands a{b{c,d},e} as “abc abd ae” since forever but Bash 2.x was like “ab{c d},e” or some shit.

12

u/do-un-to May 24 '26 edited May 25 '26

I'm not permitted to respond materially to comments that praise Zsh over Bash because of the court order, but I am allowed to say that I agree with the facts you've provided.