Slugify and Remove Custom Characters

Tags: thunar custom action, delete, sed, rename
November 11, 2015

To learn how to use Thunar Custom Actions click here.

##Delete Spaces, Underscores, Plusses, and Hyphens in Filenames

This custom action will remove spaces, underscores, plusses, and hyphens from selected filenames. It can be customized by deleting or adding characters between the brackets: [ _+-]. So if you want to just delete spaces and plusses, then remove the underscore and the hyphen from between the brackets.

for file in %N; do mv "$file" `echo $file | sed -e 's/[ _+-]//g'`; done

Under Appears if selection contains make sure everything is checked.

##Slugify Filenames

Modifies filenames to lowercase, replaces spaces with dashes, and lowercases extension.

for file in %N; do mv "$file" "$(echo "$file" | tr -s ' ' | tr ' A-Z' '-a-z' | tr
-s '-' | tr -c '[:alnum:][:cntrl:].' '-')"; done

Under Appears if selection contains make sure everything is checked.

}