Home > Linux, Useful commands > Remove special characters recursively from file names.

Remove special characters recursively from file names.

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
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: