Having issues trying to copy just jpg,png & JPG files starting with IMG_0000 from one directory to another. I have found the correct expression but I am struggling to make it work.
Below I have put the correct Regex as well as my code so far. The directory I am copying from is /root/memory and the target directory is /root/photoarch. Please note that inside /root/memory there are multiple sub-directories and multiple different file types.
Regex:
IMG_[0-9]{4}.[jpg,png,JPG]{3}
Code:
#!bin/bash
mkdir photoarch
find "/root/memory" -regex '.*IMG_[0-9]{4}.[jpg,png,JPG]{3}' -exec cp {} "/root/photoarch"\;
[]is a set of characters to look for, which means[jpg,png,JPG]{3}is looking for 3 characters in the set, so this will match any combination of the charactersjJpPngG,. You need to use a group instead such as(?:jpg|png|JPG). You should probably use(?:[jJ][pP][eE]?[gG]|[pP][nN][gG])or(?i)(?:jpe?g|png)(?-i)(assuming bash allows this) instead. If you don't care aboutIMGbeing uppercase (you're ok with a case-insensitive search), simply use the case-insensitive flag (typicallyi) and(?:jpe?g|png).find.findhow to interpret that regex by adding-regextype posix-egrepto thefindcommand