从文件名bash脚本中删除特殊字符

时间:2015-06-07 08:33:02

标签: bash

我有这个bash脚本,我需要修改它所以它还包括“=”和“;”。

感谢。

#!/bin/bash


find . -depth -name "*[,&<>*?|\":'()]*" |     # Find all files or folders containing 'bad' characters.
while read FILEDIR                            # Read them line-by-line.
do
        DIR="${FILEDIR%/*}"                   # Get the folder its inside
        FILE="${FILEDIR/*\/}"                 # Get the plain name.
        NEWFILE="${FILE//[,&<>*?|\":\'()]/_}" # Substitute _ for bad things.
        mv "$DIR/$FILE" "$DIR/$NEWFILE"  # Rename it.
done

1 个答案:

答案 0 :(得分:0)

NEWFILE=$(echo -n "$FILE" | tr -c '[:alnum:][:blank:]_-' _)

不幸的是,它会花费每个文件的分叉。

相关问题