2023-11-07 16:48:09 +01:00
|
|
|
#!/bin/bash
|
2023-11-07 09:02:41 +01:00
|
|
|
|
|
|
|
# todo : add a dry-run
|
|
|
|
|
|
|
|
sanitize() {
|
2023-11-07 16:48:09 +01:00
|
|
|
shopt -s extglob
|
2023-11-07 09:02:41 +01:00
|
|
|
|
|
|
|
filename=$(basename "$1")
|
|
|
|
directory=$(dirname "$1")
|
|
|
|
|
|
|
|
filename_clean="${filename//+([^[:alnum:]_-\\.])/_}"
|
|
|
|
|
2023-11-07 16:48:09 +01:00
|
|
|
if [[ $filename != "$filename_clean" ]]; then
|
2023-11-07 09:02:41 +01:00
|
|
|
mv -v --backup=numbered "$1" "$directory/$filename_clean"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
export -f sanitize
|
2023-11-07 16:48:09 +01:00
|
|
|
find "$1" -depth -exec bash -c 'sanitize "$0"' {} \;
|