Task is to delete all images within a month's archive that are not assigned to a post and have not been uploaded by the admin (user_id 1). The number of affected images is large (>50.000 images), so they have to be deleted image by image.
Command: Delete unattached images line by line and exclude the admin:
for id in $(wp db query "SELECT ID FROM wp_posts WHERE post_date>='2020-11-01' AND post_date<='2020-11-30' AND post_type='attachment' AND post_parent=0 AND post_author !='1'" --silent --skip-column-names)
do
wp post delete --force $id
done
Is the solution