tags:

views:

36

answers:

2

I want to replace 'localhost' with an actual ip like '1.1.1.1' in every file in a directory including subfolders, plus I want it to log the filenames it changed. I'm having a difficult time doing this, what command should I use?

+1  A: 

find /path/to/all/files -type f -exec sed -i 's/localhost/IP/g' {}\; should work. Or you get an idea of how to make sed work on every file that find finds.

vpit3833
When I do this I get a "missing argument to 'exec'" error.
pg
It needs a semicolon at the end, that's what causes the "missing argument" error.
David Zaslavsky
@David: thank you for the comment. I will proof read my answers. Included the missing semi-colon.
vpit3833
+2  A: 
grep -r --files-with-matches localhost *|tee changed_files|xargs sed -i 's/localhost/1.1.1.1/g'

The files changed will be logged to changed_files.

Matthew Flaschen
Why specify `-n1`?
Kaleb Pederson
@Kaleb, you're right. It wasn't needed.
Matthew Flaschen