So any code generating file names containing new line characters (or anything other than alphanumeric and space should be fix. If that is not possible, like when you do not own the code generating them, and we still need to process such files with our own tools then it is better if we just rename them.
I have scripted this post as:
#!/bin/bash -e #/usr/sbin/fixInvalidFileName.sh USAGE="Usage: `basename $0` <filePath>" if [ $# -ne "1" ] then echo $USAGE exit 1 fi file=$1 pattern=$'[\r\n]' if [[ "$file" == *$pattern* ]]; then mv "$file" "${file//$pattern/}" fiNow you can use it like:
find . -name "*" -exec /usr/sbin/fixInvalidFileName.sh {} \;And the result would be newlines stripped out the file name.
No comments:
Post a Comment