Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am in the process of selling a network of 60 sites, they all have adsense with the same publisher id (google_ad_client="pub-xxxxxxxxxxxxxxxx") in all the files in the /home/ folder.

How can I do a mass search/replace from ssh to change my id to the buyer id?

share|improve this question
up vote 4 down vote accepted

So you want to ssh to each machine and make that change? Should be pretty straightfoward with ssh and expect. Check out this stackoverflow question about that approach. Basically you just need to use expect to automate the ssh logins and then run something like this on every server (all via expect):

find /home/ -type f -maxdepth 1 -print0 | xargs -0 sed -i 's/pub-xxxxxxx/pub-12345/'

that will use sed to edit every file in-place in /home (and no lower in the tree) and replace occurrences of the first string with the latter.

If this is more than a one-time thing you can look into automating this more cleanly, like setting up passwordless ssh logins to eliminate the expect step. However if I understand your question correctly you are really looking for a one-time solution, which is why I say use expect this way.

share|improve this answer
Thanks that helped, I actually only need to login on one machine as root, it's a dedicated server. – jejasmin Jan 10 '11 at 23:30
Oh ha, then that's a lot easier. Just log in and run a sed script! – Phil Hollenback Jan 11 '11 at 0:17
For me, it says find: warning: you have specified the -maxdepth option after a non-option argument -type, but options are not positional (-maxdepth affects tests specified before it as well as those specified after it). Please specify options before other arguments. I'm on centos 6! Thank you! – Kleidi Jan 26 at 2:35
Ok then just try find -maxdepth 1 /home/ -maxdepth1 -print0 etc – Phil Hollenback Jan 26 at 6:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.