There is an answer from SuperUser, which renames filenames containing whitespace:
for f in *\ *; do mv "$f" "${f// /_}"; done
The part I don't understand is *\ *
.
The author wrote that:
*\ *
selects all files with a space in their name as input for the the for loop. The pattern X selects all files with X in their name, and for the special character space, we have to escape it with a slash so that bash doesn't treat it as separating different arguments.
Since *
does not match a space, why does *\ *
also match files with multiple space character when it only has one space in it?
*
does match spaces. Why do you think it doesn't?