-
Convert file extensions to lower case (rename, Linux shell script)
Posted on November 20th, 2012 5 commentsI am using Unison more and more, and recently I decided to try to use it to keep my digital image archive synchronized. It seems that at some time I have not explicitly instructed the image importing program of the day (Shotwell being the program I mostly use) to rename the image files in order to consequently use a lower case file extension.
Thus I felt the need to rename all image files (in the shotwell folder) to a lower case file extension. There may or may not be a program out there to do this, but I wrote my own shell script for this purpose. My experience is that I learn more by doing it myself, and a lot of the tricks I learn can be reused the next time.
This is how I did it, I cannot promise that it will work for anyone else (indentation lost in WordPress):
#!/bin/sh
imgdir=‘pwd‘
imgucext=$(find ${imgdir} –type f –name ‘.’ | awk –F’.’ ‘NF > 0 { print $NF }’ | sort | uniq | LC_ALL=C egrep ”[[:upper:]]”)
for ucext in ${imgucext}
do
lcext=$(echo ${ucext}|awk ’{print tolower($0)}’)
find ${imgdir} –type f –name “.${ucext}” –print | \
sed ’{s/ /\\ /g}’ – | \
sed ’{s/(/\\(/g}’ – | \
sed ’{s/)/\\)/g}’ – | \
sed ”{s/\(.\.\)${ucext}$/mv –n –v \1${ucext} \1${lcext}/g}” – | \
sh
done
Starting in the current folder/directory, I check what upper case extensions are present, find all files using them, rewrite spaces and parenthesis for the shell, and create a rename command for each file, which is then piped to the shell. For debugging purposes the sh close to the end would be substituted for a cat.5 responses to “Convert file extensions to lower case (rename, Linux shell script)”

-
I have been exploring for a bit for any high-quality articles or
weblog posts on this sort of area . Exploring in Yahoo I at last stumbled upon
this web site. Studying this info So i am glad to exhibit that I have an incredibly good uncanny feeling
I found out exactly what I needed. I most definitely will
make sure to don?t put out of your mind this
web site and give it a glance regularly. -
Unquestionably believe that which you said. Your favourite justification appeared to be at
the web the simplest thing to remember of.
I say to you, I definitely get annoyed even as
folks consider worries that they plainly do not recognise about.
You managed to hit the nail upon the top as smartly as outlined out the entire
thing without having side-effects , folks could take a signal.
Will likely be again to get more. Thanks
Leave a reply
-
