I have a timelapse cam taking pictures every few minutes, no matter if its day or night. I want to pass only the daytime images to ffmpeg to create a movie. So I have a folder full of images with their timestamps in the filename:
photo_2023-02-24_10-48-23.jpg
photo_2023-02-24_03-42.jpg
photo_2023-02-23_23-12-06.jpg
photo_2023-02-23_12-22.jpg
photo_2023-02-23_12-22-03.jpg
...
I want to get all images that were taken in daytime (e.g. between 08-00 and 17-00).
So far I came up with this regex. I want to select the "hour" in the name. How do I reuse that part to compare it in the next step?
find -E . -type f -regex ".*/photo_[0-9]{4}-[0-9]{2}-[0-9]{2}_([0-9]{2}).*" -exec bash -c \
'fn=${0##*/}; h=${HOUR};
[[ $h -ge 8 && $h -le 17 ]] && echo "$0"' {} \;
Helpful so far: Find all files containing the filename of specific date range on Terminal/Linux
If you want to get all files containing number from 08 to 16 (including) in hour position, you could use this command:
find . -type f -regex ".*/photo_[0-9]{4}-[0-9]{2}-[0-9]{2}_(0[89]|1[0-6]).*"