I'm writing a script to move files (Dropbox Camera Uploads, for instance) to year named folders, like this:
#!/bin/bash
#
# Separate (camera) images on directory
# to year named folders.
#
# All files must be named as "yyyy-mm-dd HH:MM:SS.ext"
#
for img in *.{jpg,jpeg,png}; do
year=${img:0:4}
[ -d "$year" ] || mkdir "$year"
mv -iv "$img" "$year/"
done
The script works as expected for matchin files, but when there isn't any file with some extension, expands to *.ex
(first two extension chars). Then it creates empty directories as follows:
'*.jp'
'*.jp'
'*.pn'
How can I just ignore no matching files?