Fastest way to rename filenames with space to dash in linux

I want to mass rename hundred of filenames like
filename 001.jpg to filename-001.jpg

filename 099.jpg to filename-099.jpg

I use this command to rename all in few seconds in my MacBook Pro.
I think it is fine to run in any linux.

for f in *\ *; do mv "$f" "${f// /-}"; done

Author: Justin Soo