英文:
Find files between time from file names timestamp
问题
我有一个间隔几分钟拍照的延时摄像机,无论是白天还是黑夜,都会拍照。我想只传递白天的照片给ffmpeg来制作电影。
因此,我有一个文件夹,里面装满了带有时间戳的图像文件名:
```bash
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
...
我想获取所有白天拍摄的图像(例如在08:00和17:00之间)。
到目前为止,我想出了这个正则表达式。我想选择文件名中的“小时”部分。我如何重复使用该部分以在下一步中进行比较?
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"' {} \;
到目前为止,这是有帮助的:
https://stackoverflow.com/questions/46951256/find-all-files-containing-the-filename-of-specific-date-range-on-terminal-linux
<details>
<summary>英文:</summary>
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?
```sh
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:
https://stackoverflow.com/questions/46951256/find-all-files-containing-the-filename-of-specific-date-range-on-terminal-linux
答案1
得分: 1
要获取在小时位置包含从08到16(包括)的所有文件,您可以使用以下命令:
```sh
find . -type f -regex ".*/photo_[0-9]{4}-[0-9]{2}-[0-9]{2}_(0[89]|1[0-6]).*"
英文:
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]).*"
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论