jadelennox: Demonic Tutor, Jadelennox: my Magic card (demonic tutor)
jadelennox ([personal profile] jadelennox) wrote in [community profile] command_liners2013-06-02 11:50 pm

curly braces on the shell

So a fun shell trick (works in bash, tcsh, zsh) involves curly brace expansion. Different shells have different complexities, but the simplest case that works in all shells is

mv movies-19{92,93}.txt

which expands

mv movies-1992.txt movies-1993.txt

I use this daily. Usually to say mv foo.sh{,.bak} which translates to mv foo.sh foo.sh.bak
troisroyaumes: Painting of a duck, with the hanzi for "summer" in the top left (Default)

[personal profile] troisroyaumes 2013-06-03 03:58 pm (UTC)(link)
Wow, why didn't I know this before? Thank you, that is such a timesaver.
cxcvi: Red cubes, sitting on a reflective surface, with a white background (Default)

[personal profile] cxcvi 2013-06-05 12:42 pm (UTC)(link)
I know I've used that syntax before, but the usage in the last line is new to me. That's actually really clever.
afuna: Cat under a blanket. Text: "Cats are just little people with Fur and Fangs" (Default)

[personal profile] afuna 2013-06-05 03:43 pm (UTC)(link)
I love this and ilu.
pauamma: Cartooney crab wearing hot pink and acid green facemask holding drink with straw (Default)

[personal profile] pauamma 2013-06-07 04:22 pm (UTC)(link)
ISTR first finding out about this on whatever *csh ran on SunOS 3 and SunOS 4. (IIRC, straight 4.xBSD csh)
brownbetty: (Default)

[personal profile] brownbetty 2013-06-07 08:23 pm (UTC)(link)
I used this on a rather complicated rsync recipe the other day and felt very clever.

[personal profile] schilling_klaus 2017-12-02 11:32 pm (UTC)(link)
You can even use serveral curly-brace-expressions, and they will be expanded like multiplying sums in arithmetics.

{foo,bar}{.tex,.pdf}
becomes
foo.tex foo.pdf bar.tex bar.pfd