Here is some nice code for converting all jpg to webp and also code for deleting all files excluding .webp or any other you want. This is for my personal reference 🙂
nohup find . -type f -regex ".*\.\(jpg\|jpeg\)" -exec mogrify -quality 40 -format webp {} \; -print &
find . -type f ! \( -name "*.webp" \) -exec rm -rf {} \;