Linux - Replacing spaces in the file names Linux - Replacing spaces in the file names linux linux

Linux - Replacing spaces in the file names


This should do it:

for file in *; do mv "$file" `echo $file | tr ' ' '_'` ; done


I prefer to use the command 'rename', which takes Perl-style regexes:

rename "s/ /_/g" *

You can do a dry run with the -n flag:

rename -n "s/ /_/g" *


Use sh...

for i in *' '*; do   mv "$i" `echo $i | sed -e 's/ /_/g'`; done

If you want to try this out before pulling the trigger just change mv to echo mv.