This felt like a command-line blind spot: is it possible to invert a glob?
What’s the opposite of
rm *.mp3? How would you delete everything except the
It turns out that there’s a syntax for that:
if you put
shopt -s extglob in your .bashrc. There are no downsides
to using that config. Extended globbing allows you to do other things too.
Without extended globbing, you could try:
but that won’t account for filenames with spaces and other characters that would need to be escaped.