I'm trying to search the entire file system for specific text. This command does that but it gets hung up in certain directories like '/proc':
find / -print0|xargs -0 grep whatever
What I'd like to do is only send files to grep that don't match '/sys' '/proc' '/tmp' '/lib'.
Update: After the help from Gary below I needed to add a few more excluded directories so I decided to write a python script to do this:
#!/usr/bin/python
import sys
import os
from os.path import join, getsize
import time
import re
search = "192.168.30"
searchRoot = "/"
reobj = re.compile(r"^/var|^/dev|^/proc|^/sys|^/bin|^/boot|^/home|^/lost|^/media|^/misc|^/mnt|^/net|^/sbin|^/selinux|\.log")
start = time.time()
for root, dirs, files in os.walk(searchRoot):
for name in files:
fullPath = os.path.join(root, name)
if not reobj.search(fullPath):
try:
fileSize = os.path.getsize(fullPath)
if (fileSize < 51200):
try:
#print fullPath
fileobj = open(fullPath, 'r')
text = fileobj.read()
fileobj.close()
index = text.find(search)
if (index > -1):
print index, ":", fullPath
sys.stdout.flush()
except:
pass
except:
pass
print "Completed search for", search, "in", searchRoot, "in", time.time() - start, "seconds."