Skip to content

Instantly share code, notes, and snippets.

@ckunte
Created June 4, 2017 13:58
Show Gist options
  • Save ckunte/f68e7fae942b31d4148ff3b781c2b0cd to your computer and use it in GitHub Desktop.
Save ckunte/f68e7fae942b31d4148ff3b781c2b0cd to your computer and use it in GitHub Desktop.
Remove spaces and special characters from file and folder names (in zsh)
#!/usr/bin/env zsh
autoload -U zmv
# Safety first: Always use -n switch to test changes before commit.
# Clean up file names in subdirectories and remove special characters
zmv -n '(**/)(*)' '$1${2//[^A-Za-z0-9.-]/_}'
# Replace spaces in filenames and folders with a hyphen
zmv -n '* *' '$f:gs/ /-'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment