Rename Files Fast from the Linux CLI
by errr on Jan.14, 2010, under Linux
So today I moved our web root from this OLD system to our new server. First things first I tried to hit some of the links and I was served given the option to d/l the file… Well I could go to the Web server config file and tell it to parse these files as php, or how about we ditch the .php3 for something this decade… like .php So I go to our web root and look for all the files that end in .php3
find . -iname “*.php3″ -print
Nice. Now I have a huge list of files here.. How on earth can I rename them with out this taking all day… I used rename like so:
find . -iname “*.php3″ -print |xargs rename -n ’s/\.php3/\.php/’
This command will NOT actually change ANYTHING on your system. The -n flag says to run through as a test and tell me what you would be doing if I wanted it done… I can see from this output that I do indeed want to run this command.
find . -iname “*.php3″ -print |xargs rename -v ’s/\.php3/\.php/’
Now this time it did go though and rename and it printed to the screen what it did (thats what the -v flag does verbose). Now I can go though and edit the index file that pointed to these php3 files and remove that 3. Simple and now I dont have that silly 3 on the file names any more.