Shell – change entire directory tree to lower-case names

case sensitivityshell

I'm working on a website conversion. The files as they were linked and served from the web server were case insensitive. But, I've made a dump of the site on my linux system and I'm writing scripts to migrate data. The problem is that I'm running into case sensitivity problems between link strings in the pages and the actual word case on the file system.

For instance, a page might have a link like <a href='/subfolder/PageName.asp'> while the actual file is /subfolder/pagename.asp. Likewise with images — <img src='spacer_sm.gif'> might be Spacer_Sm.gif.

So my thought is to change all directory and filenames to their lower-case equivalents for the site download. How do I do this (and might there be a better way?)

Even if there are unix commands that have case-insensitve switches, I'm using php, so not all of the filesystem commands there have options for case sensitivity.

Best Answer

I don't know whether your unix-flavor has a rename. Many Linuxes have, and it is part of a perl-package, if you search for a repository.

find ./ -depth -exec rename -n 'y/[A-Z]/[a-z]/' {} ";"

Above version with

rename -n 

doesn't really perform the action, but only print what would be done. You omit the -n to do it for real.