Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save jamescreate/c70a05bb07e66e2f317f9ce34b2307d4 to your computer and use it in GitHub Desktop.

Select an option

Save jamescreate/c70a05bb07e66e2f317f9ce34b2307d4 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment