for target in *, do mv "$target" "${target// /_}"; done
Thank you. That worked.
]]>for target in *, do mv "$target" "${target// /_}"; done
#edit thanks seth
]]>Some linux distributions call it "prename" or "file-rename", and/or offer an option to choose between the two for the /usr/bin/rename file.
]]>I am trying to write a script that will substitute spaces in file names into underscores. mv command does not work, as it expects a directory as the last argument for some reason. I read about rename command and so I tried the following;
rename 's/\ /_/g' ${1}
This produces an error stating it does not have enough arguments for some reason. Upon reading the man page I found out that the correct way of writing the command is the following (which works but not completely);
rename \ _ ${1} # There is a space after backslash.
This works but the problem is it only replaces the first ever blank space in the name of the file. Searching the internet, I only found the first mentioned use of the command.
How do I make it so that the command replaces all of the spaces in the file name?
]]>