Archive for December, 2012

Remove special characters recursively from file names.

31/12/2012 Leave a comment
e='s/[ #,;]//g'; find . | while read f;do c=`basename "$f"`; b=`echo ${f%$c} | sed "$e"`; rename -v "$e" "$b`basename "$f"`"; done

This command will scan current directory and change file/folder name when found bellow characters: ” #,;”

Very useful if you plan e.g. copy Maildir from linux (extX) to windows (ntfs):

./Maildir/cur/1332130272.18962_0.debian:2, renamed as ./Maildir/cur/1332130272.18962_0.debian2
./Maildir/cur/1332389482.29532_0.debian:2, renamed as ./Maildir/cur/1332389482.29532_0.debian2
./Maildir/cur/1332098770.29631_0.debian:2, renamed as ./Maildir/cur/1332098770.29631_0.debian2
./Maildir/cur/1330798043.25409_0.debian:2, renamed as ./Maildir/cur/1330798043.25409_0.debian2

Categories: Linux, Useful commands