Testado e funcionando.
#!/usr/bin/env bash
#delete RAW if Preview img doesn't exists
createTest() {
local dir=$1
rm -rf "$dir"
mkdir -p "$dir"/05/{"event 1","event 2"}/RAW/
mkdir -p "$dir"/05/RAW
touch "$dir"/05/RAW/image{1..3}.RAW; touch "$dir"/05/image{1..2}.jpg
touch "$dir/05/event 1/RAW/"image{4..6}.RAW; touch "$dir/05/event 1/"image{4..5}.jpg
touch "$dir/05/event 2/RAW/"image{7..9}.RAW; touch "$dir/05/event 2/"image{7..8}.jpg
}
deleteRAW() {
local jpg=
local t=
shopt -s globstar;
for raw in "$1"/**/*.RAW; do
t=${raw##*/}
jpg=${raw%/*}/../${t%.*}.jpg
if [[ ! -f $jpg ]]; then
rm -f "$raw"
echo "Removed $raw"
fi
done;
}
for dir; do
createTest "$dir"
deleteRAW "$dir"
done
Teste:
]➬./delete.sh 2016
Removed 2016/05/RAW/image3.RAW
Removed 2016/05/event 1/RAW/image6.RAW
Removed 2016/05/event 2/RAW/image9.RAW
Teste com espaços:
]➬./delete.sh "2016 spaces"
Removed 2016 spaces/05/RAW/image3.RAW
Removed 2016 spaces/05/event 1/RAW/image6.RAW
Removed 2016 spaces/05/event 2/RAW/image9.RAW
com vários dirs:
]➬./delete.sh "2016 spaces" 2017
Removed 2016 spaces/05/RAW/image3.RAW
Removed 2016 spaces/05/event 1/RAW/image6.RAW
Removed 2016 spaces/05/event 2/RAW/image9.RAW
Removed 2017/05/RAW/image3.RAW
Removed 2017/05/event 1/RAW/image6.RAW
Removed 2017/05/event 2/RAW/image9.RAW
Você pode se sentir livre para testá-lo usando outras soluções comentando a chamada deleteRAW na última linha.
for dir; do
createTest "$dir"
#deleteRAW "$dir"
done
Felicidades e melhor sorte. :)