Bulk Replace Spaces in File Names

Introduction

This is the easiest way I've found to replace spaces in file names with another character for example underscore.

Solution

At a bash prompt, use rename:
find -name "* *" -type d | rename 's/ /_/g'    # do the directories first
find -name "* *" -type f | rename 's/ /_/g'
This does the trick nicely.

Leave a comment

Your email address will not be published. Comments are moderated before appearing.