Remove spaces from file names via bash

Feb 29, 2016 | General

if you need a simple way to remove spaces from file names and replace with an underscore or a hyphen or whatever else here is a bash one liner. You can also do this via python or perl or most likely via php (why? o.0) but since bash / zsh is here and readily available for me I choose to use bash / zsh.

Remove spaces and replace with underscore:

remove spaces and replace with hyphen :

Remove spaces completely:

Be careful with he above as it will remove all spaces from file and directory names.

hope this helps. if you have a better way of doing it comment and let me know 🙂