Skip to content

Instantly share code, notes, and snippets.

@jamescreate
jamescreate / gist:c70a05bb07e66e2f317f9ce34b2307d4
Created June 1, 2017 15:26
Rename files in current directory, replacing space char with hyphen
#!/bin/bash
ls -1 | while read file;
do
if [[ $file =~ " " ]]; then
newname=` echo "$file" | tr ' ' '-' | tr -s '-' `
printf "Renaming %s to %s \n" "$file" "$newname"
mv "$file" "$newname"
fi
done