Using this good method for using find
Getting dates is explained in this answer
Expanding filenames in find command explains the complexity of passing the filename into what amounts to a shell script.
Command below finds all files newer than last monday and not newer than sunday (could be last-sunday), the file name must start with C
and end with .csv
, after finding the file execute a shell and pass the found path in as argument 1 $src
and then replace olddir
with newdir
in $dst
. If no dst directory exist, create dst directory. Move the file from olddir
to newdir
.
gfind olddir \
-newermt "$(date -dlast-monday +%Y%m%d)" \
! -newermt "$(gdate -dsunday +%Y%m%d)" \
-name C*\.csv \
-exec bash -c \
'src=$1 && \
dst="${1/#olddir/newdir}" && \
[ -d $(dirname $dst) ] || \
mkdir -p $(dirname $dst) && \
mv $src $dst' \
bash \{\} \;