Skip to content

Instantly share code, notes, and snippets.

@plesiv
Last active November 10, 2015 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save plesiv/5e39c46e2620774f708a to your computer and use it in GitHub Desktop.
Save plesiv/5e39c46e2620774f708a to your computer and use it in GitHub Desktop.
Shell functions for filename normalization
# normalize string given as an argument
n() { sed -e 's/^[ -]\+//' -e 's/[ -]\+$//' -e 's/[ ()-]\+/-/g' -e "s/'//g" | tr '[:upper:]' '[:lower:]' $1; }
# normalize name of the single file (renames file)
m() { mv "$1" "$(echo $1 | n)"; }
# normalize names of all files in the current directory
f() { for i in *; do m "$i"; done; }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment