I'm using the following code to sort recordings and captures from my CCTV into dated sub directories that are more than a day old.
Is there any way to reference the results of the echo grep date section of the IF code as a variable so that it can be used when creating a folder?
I could just create a variable on a separate line with another use of grep (or define the variable and reference it in the IF statement) but would prefer if it were all on one line.
File names are similar to 'MDAlarm_20160417-120925.jpg' so the contents of the variable would be 2016-04-17.
for f in ~/FI9803P_00626E5755DE/**/*;
do
if [[ `echo $f | grep -oP '\d{8}' | date -f - +'%Y-%m-%d'` != `date +'%Y-%m-%d'` ]]; then
mkdir -p $(dirname $f)/$varFromIF; echo "Made it" #mv $f $(dirname $f)/$varFromIF
fi
done
findwith option-mtimeto find files older than a day. That's way faster than usingdateon each file:find ~/FI9803P_00626E5755DE/ -type f -ctime +1 | while read f; do mkdir …; done.