I have multiple screenshots since 2008 with name like "screenshot-2010-13-12.jpg". I need to copy screenshots since 2010 to 2019. I tried different options with -name and -regex , but cant find the way. The only success with regex is finding by format, nothing more.
2 Answers
If you want to be strict about the format something like this can do the work:
find . -name "screenshot-201[0-9]-??-??.jpg" -type f
This will search for files whose name starts with screenshot-201
, then has a digit, then dash, two characters, dash, two characters and .jpg
To generalise to arbitrary range of dates, in zsh
you could do:
cp screenshot-????-??-??.jpg(.e['
[[ $REPLY >= screenshot-2010-02-12.jpg &&
$REPLY <= screenshot-2019-09-21.jpg ]]']) /some/dir/
Or:
cp screenshot-????-??-??.jpg(.e['
[[ ${REPLY//[^0-9]} = <20100212-20190921> ]]']) /some/dir/
To copy regular (with .
) files in the 2010-02-12 to 2019-09-21 range for instance.
If they're not in the current working directory but you need to search for them in any level of subdirectories:
cp -i -- **/screenshot-????-??-??.jpg(.e['
[[ $REPLY:t >= screenshot-2010-02-12.jpg &&
$REPLY:t <= screenshot-2019-09-21.jpg ]]']) /some/dir/
(here adding -i
to mitigate the risk in case several files with the same name are found in directories).
screenshot-201aaa.doc
Screenshot....
,screenshot-2013
, but notscreenshot-2019-13-12.jpg
. And will show also the directories.