Find files that do not contain a string

To find files that do NOT contain a specific string you can do the following:
[code lang=”bash”]find -name “ifcfg-eth0:*” -type f ! -exec grep -q ONBOOT {} \; -exec ls {} \;[/code]

will list all files named ifcfg-eth0:* that do not contain the string ONBOOT.

You can script this up as such:

[code lang=”bash”]for i in `find -name “ifcfg-eth0:*” -type f ! -exec grep -q ONBOOT {} \; -exec ls {} \; |awk -F\/ ‘{print $2}’`; do echo ONBOOT=yes >> $i ; done[/code]

to add the required ONBOOT=yes line to the config.

Leave a Reply