Here is the Python code :
#!/usr/bin/python
import os
indir = ‘/var/www/mysite‘ #!Folder of your localhost site.
for root, dirs, filenames in os.walk(indir):
for f in filenames:
log = open(os.path.join(root, f), ‘r+’)
f=log.read()
n=f.replace("http://localhost", "http://mysite.com")
log.seek(0)
log.truncate()
log.write(n)
log.close()
print "Successfully Replaced."
Change the location of your localhost site and the localhost link and mysite link to your site address above if you want to change it. Then save this file as link-replace.py. Make the file executable and run it in terminal. The program will automatically replace the links and will print out "Successfully Replaced" if the program completed replacing links.