Archived
1
0
Fork 0
This repository has been archived on 2024-10-31. You can view files and clone it, but cannot push or open issues or pull requests.
dotfiles/simpleDots/bin/sanitize_files.sh

20 lines
445 B
Bash
Raw Normal View History

2022-02-18 00:28:49 +01:00
#! /bin/bash
sanitize() {
shopt -s extglob;
filename=$(basename "$1")
directory=$(dirname "$1")
#filename_clean="${filename//+([^[:alnum:]_-\.])/_}"
filename_clean=$(echo -n $filename | tr --complement --squeeze-repeats "[:alnum:]./" "_")
if (test "$filename" != "$filename_clean")
then
mv -v --backup=numbered "$1" "$directory/$filename_clean"
fi
}
export -f sanitize
find $1 -depth -exec bash -c 'sanitize "$0"' {} \;