Pages

Thursday, March 1, 2012

Linux: searching inside files

Three ways for searching fro specific string inside file with input to separate file or terminal session

1. Use find and filter results with grep
find /var/www -type f -print0 | xargs -0 grep -i 'old string'

or

find /var/www -type f -print0 | xargs -0 grep -li 'old string'

2. Use grep
grep -Rli 'old string' /var/www > list_of_files

-l option will show only file names without specific line

3. Using ack

ack -la /var/www