mv -t newfolder *.(png|jpg)
Is the zsh
syntax, but you need to enable it with:
setopt extended_glob
Strictly speaking, you should write it:
mv -t newfolder -- *.(png|jpg)
As otherwise, if some file names start with a -
character, it won't work properly.
mv -t newfolder -- *.@(png|jpg)
is the ksh
syntax. It can be recognised by zsh
if you turn the kshglob
option on (setopt kshglob
) and by bash if you turn the extglob
option on (shopt -s extglob
).
However note that ksh
and bash
both suffer from one problem in that instance: if there's no png
nor jpg
file, *.@(png|jpg)
will be passed untouched to mv
, and if there does exist a file by that (admittedly unusual) name, it will be moved to newfolder
.
In bash
, you can avoid that problem by turning on the failglob
option. In ksh
(recent versions of ksh93 only), the best you can do is write ~(N)*.@(png|jpg)
(which would be the equivalent of nullglob
in bash or the (N)
globbing qualifier in zsh), which would cause the pattern to expand to nothing if there's no matching file, and you would then get an error from mv
.
mv -t newfolder *.{png,jpg}
Do you need it for a specific shell?nullglob
is not set (mv: rename *.foo to newfolder/*.foo: No such file or directory
), or fail entirely iffailglob
is set (bash: no match: *.foo
).mv -t newfolder *.png *.jpg
sincemv
supports any number of files named on the command line (up to the command line length limit imposed by the shell, which will be a concern with regex filename matching as well).