renaming non-ascii file names
Mon, 08/14/2017 - 12:52 — sandipBelow script replaces non-ascii character with an underscore in file/folder names.
Before running the below script, cd to the folder with files that need renamed first.
#!/bin/bash
# rename2ascii.sh
# Replaces non-ascii character with an underscore.
function rename_to_ascii() {
echo -n "$1" | \
perl -ne '$new = $_; if($new =~ s/[^[:ascii:]]/_/g) {
print("Renaming $_ to $new\n");
rename($_, $new);
}'
}
export -f rename_to_ascii
find -depth -exec bash -c 'rename_to_ascii "$0"' {} \;
- sandip's blog
- Login or register to post comments