Find the answer to your Linux question:
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 ...
  1. #1
    Just 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?

  2. #2
    Just Joined!
    Join Date
    Aug 2011
    Posts
    48
    Code:
    find / -exec grep -li "some text" {} \; | awk '{print "chown root "$0";chmod 600 "$0}'
    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}' | bash
    Again be careful!!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...