I have a mix of different files in my folder and I thought I can simply do:
mv '*.(png|jpg|gif)' images/
to have them moved to the image folder. But it doesn't work... any thoughts?
This question came from our site for professional and enthusiast programmers.
Use a feature in bash called brace expansion
And what shell are you using?
Goxu has the correct answer. There's no reason you should do something more esoteric if you can do it in a more simple and understandable manner.
In the end, the shell expands the command to include all the files before passing the list to the
However, if you want to be Mister Fancy Pants, you should know that both Bash and Kornshell (both available on OS X) can do the following using extended glob expressions:
Extended glob expressions (aka pattern matching) is really helpful when you want to remove everything from a directory except for one file. For example, you expanded a tar archive, and want to delete all the files except for the tar archive:
The thing with Bash is that you have to turn on this functionality via the shopt command first:
Take a look at the Bash manpage and look at the section on Pattern Matching. It contains a lot of neat shell tricks that not too many people know about. It gives your shell some secret super powers, but always remember to use those powers to help mankind and never for evil.