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?
Asked by glacier
(391 rep)
Apr 22, 2025, 01:46 PM
Last activity: May 19, 2025, 04:45 PM
Last activity: May 19, 2025, 04:45 PM