[How To] Unix command to replace all spaces in file names with underscore

rename command comes handy when one wishes to replace spaces in all the file names with underscore (or any other character for that matter).

Below syntax tells the shell to substitute all spaces (' ') in the name of all the files in current directory with underscore ('_').


$ rename 's/ /_/' *

The below snapshot from the terminal illustrates the same.


rename command to replace spaces with underscores [click on the image to enlarge]