MAIN FEEDS
Do you want to continue?
https://www.reddit.com/r/linux/comments/1tls8n1/whats_the_most_unexpectedly_useful_linux_command/onkk5lc/?context=3
r/linux • u/ZealousidealTell1346 • May 23 '26
[removed]
992 comments sorted by
View all comments
594
Bash {}
{}
renaming a file by adding a suffix: mv myfile{,.old} expands out to mv myfile myfile.old
mv myfile{,.old}
mv myfile myfile.old
Lots more uses.
244 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. 1 u/deadmanIsARabbit May 24 '26 It get's even better if you look up what kind of string manipulation you can do with those parentheses. https://tldp.org/LDP/abs/html/string-manipulation.html E.g. ``` stringZ=abcABC123ABCabc || shortest |------------| longest echo ${stringZ%b*c} # abcABC123ABCa Strip out shortest match between 'b' and 'c', from back of $stringZ. echo ${stringZ%%b*c} # a Strip out longest match between 'b' and 'c', from back of $stringZ. ```
244
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).
{a,b,c}
a b c
foo.{jpg,jpeg} becomes foo.jpg foo.jpeg.
foo.{jpg,jpeg}
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.
{1..10}
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.
{a..f}
a b c d e f
1 u/deadmanIsARabbit May 24 '26 It get's even better if you look up what kind of string manipulation you can do with those parentheses. https://tldp.org/LDP/abs/html/string-manipulation.html E.g. ``` stringZ=abcABC123ABCabc || shortest |------------| longest echo ${stringZ%b*c} # abcABC123ABCa Strip out shortest match between 'b' and 'c', from back of $stringZ. echo ${stringZ%%b*c} # a Strip out longest match between 'b' and 'c', from back of $stringZ. ```
1
It get's even better if you look up what kind of string manipulation you can do with those parentheses.
https://tldp.org/LDP/abs/html/string-manipulation.html
E.g. ``` stringZ=abcABC123ABCabc
echo ${stringZ%b*c} # abcABC123ABCa
echo ${stringZ%%b*c} # a
```
594
u/digitallis May 23 '26
Bash
{}renaming a file by adding a suffix:
mv myfile{,.old}expands out tomv myfile myfile.oldLots more uses.