Results 1 to 2 of 2
This is what I have so far
grep -lir "some text" *
I need to check all files on the system for this text, if the text is found I ...
- 02-07-2012 #1Just Joined!
- Join Date
- Feb 2012
- Posts
- 1
Linux Shell Script to check file for string
This is what I have so far
grep -lir "some text" *
I need to check all files on the system for this text, if the text is found I need to change the file permissions so only ROOT has read and write access.
How can this be done?
- 02-08-2012 #2Just Joined!
- Join Date
- Aug 2011
- Posts
- 48
Run this first to see if it is the commands you want to run and add some if you need to. When you are sure that it is producing the commands you want just pipe that command to your favorite shell. I used a pipe to awk because you want to run multiple commands.Code:find / -exec grep -li "some text" {} \; | awk '{print "chown root "$0";chmod 600 "$0}'
Again be careful!!Code:find / -exec grep -li "some text" {} \; | awk '{print "chown root "$0";chmod 600 "$0}' | bash


Reply With Quote