Here i post a script which gives one of the best list of answers to how to rapidly rename all files in a directory tree to lower case.
Or, a more verbose version without using "rename".
Read the article for other options, and visit the web site for other problems with solutions.
Other Solutions:
Thanks
Pure bash form
A concise version using "rename" command.find my_root_dir -depth -exec rename 's/(.*)\/([^\/]*)/$1\/\L$2/' {} \;
This avoids problems with directories being renamed before files andtrying to move files into non-existing directories (e.g. "A/A" into"a/a").Or, a more verbose version without using "rename".
for SRC in `find my_root_dir -depth`
do
DST=`dirname "${SRC}"`/`basename "${SRC}" | tr '[A-Z]' '[a-z]'`
if [ "${SRC}" != "${DST}" ]
then
[ ! -e "${DST}" ] && mv -T "${SRC}" "${DST}" || echo "${SRC} was not renamed"
fi
done
Perl Script
For us perl lovers: Using Larry Wall's filename fixer$op = shift or die $help;
chomp(@ARGV = <STDIN>) unless @ARGV;
for (@ARGV) {
$was = $_;
eval $op;
die $@ if $@;
rename($was,$_) unless $was eq $_;
}
it's as simple as(where fix is of course the script above)find | fix 'tr/A-Z/a-z/'
Read the article for other options, and visit the web site for other problems with solutions.
Other Solutions:
ls | ./fix.pl 'tr/\x80-\xFF//d' # remove control characters
ls | ./fix.pl 'tr/+&#()/_/d' # get rid of some really not nice filename characters
ls | ./fix.pl 's/_+/_/g' # replace duplicate underscores with one single underscore
Thanks
0 comments:
Post a Comment