Lucas Vieites .com Logo
Lucas Vieites .com
«I intend all my puns»

Replace spaces in file names with an underscore

 

The following command searches for all files that have a space in their name (find) and for each one it finds them (while) it renames them (actually moves them with mv) replacing each space with an underscore (tr).

find . -depth -name '* *' \ | while read f ; do mv -i "$f" "$(dirname "$f")/$(basename "$f"|tr ' ' _)" ; done

Author:   ✦  Published:   ✦  Updated:   ✦