Created
June 1, 2017 15:26
-
-
Save jamescreate/c70a05bb07e66e2f317f9ce34b2307d4 to your computer and use it in GitHub Desktop.
Rename files in current directory, replacing space char with hyphen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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