<html><head></head><body>I&#39;ve found &quot;find / -xdev -type f -print0 | xargs grep string /dev/null&quot; to be completely reliable and reasonably portable.  Not to mention a lot faster.  Faster yet if you use any of the #NN arguments to xargs to batch the grep invocations.<br>
I started doing that because every time I ran grep -r, it would just hang somewhere in /etc.<br>
-Adam<br>
-Adam<br><br><div class="gmail_quote">On May 4, 2015 10:51:08 PM CDT, Trevor Cordes &lt;trevor@tecnopolis.ca&gt; wrote:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">On 2015-05-04 Gilbert E. Detillieux wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> A read on a file in /dev will almost always trigger an action<br /> (usually causing data to be read from a device, of course), but I<br /></blockquote><br />Hmm, that's a good point.  I suppose a read on a device could "steal"<br />the input another program was expecting.<br /><br />It's strange though, because now that I think about it, when I run grep<br />-r /, I'm pretty sure it's not reading all the disk block files, etc,<br />as it runs way too fast for that...<br /><br />Ah, I forgot I had this set as an alias to grep on every system I use:<br />/bin/grep -s --devices=skip<br /><br />I just checked and this new Rackspace box indeed had my alias set!<br />So the plot thickens!  So it's two possibly bugs: why was grep even<br />reading that watchdog device in the first place; and why did
reading it<br />trigger a reboot?<br /><br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> can end up in symlink-induced loops.  I'd also avoid going<br /></blockquote><br />I've never actually ended up in a symlink loop, but I can see how it<br />would be easy to run into.  I guess I don't use many dir symlinks on my<br />systems.<br /><br />Or... I just RTFM and it looks like gnu grep solved the symlink problem<br />already:<br /><br />       -r, --recursive<br />              Read  all  files  under  each  directory,  recursively,<br />following  symbolic links only if they are on the command line.  Note<br />       that if no file operand is given, grep<br />              searches the working directory.  This is equivalent to<br />the -d recurse option.<br /><br />       -R, --dereference-recursive<br />              Read all files under each directory, recursively.  Follow<br />              all symbolic
links, unlike -r.<br /><br />So that explains why I've never hit a symlink loop: I've never used -R<br />(capital).<br /><br />Ah, even better:<br />       -D ACTION, --devices=ACTION<br />              If  an input file is a device, FIFO or socket, use ACTION<br />to process it.  By default, ACTION is read, which means that devices are<br />read just as if they were ordinary<br />              files.  If ACTION is skip, devices are silently skipped.<br /><br />So that means my -D skips every "weird" file.  That means that I've<br />definitely, for sure, hit some bugs here.  There's absolutely nothing<br />now that should stop anyone from safely doing a:<br /><br />grep -r -D skip /<br /><br />on any system with modern gnu grep.<br /><br />The main reason I want to be able to do grep -r / sometimes is that I<br />need to find a string (like an IP address) that may be scattered<br />literally anywhere on the fs.  In the past when I say to myself "oh, it<br />must only be in /etc or
/var or /home", there ends up being some little<br />file in /usr (not even /usr/local) or wherever that was changed ages ago<br />for whatever reason to work around whatever problem, and it gets missed<br />unless I just "grep the whole darn thing".  And to ls / and go through<br />the 10-15 items in my brain deciding if they are greppable or <br />"system/non-greppable" takes time and is error/omission-prone, and to<br />list each one on the command line is a pain.  Now this would be easier<br />with a shell like zsh that has "negative globs" where I could specify<br />"* except /dev /sys" (ie just make an "exclude" list, not an include<br />list), but my beloved tcsh doesn't have that and I'm not ready to switch<br />to zsh yet.  And like I said before, each UNIX has its own different<br />set of "don't grep this" dirs, and they change over time (even in<br />Linux), so making a "one-alias fits all" is a non-solution.<br /><hr /><br />Roundtable mailing list<br
/>Roundtable@muug.mb.ca<br /><a href="http://www.muug.mb.ca/mailman/listinfo/roundtable">http://www.muug.mb.ca/mailman/listinfo/roundtable</a><br /></pre></blockquote></div><br>
-- <br>
Sent from my Android device with K-9 Mail. Please excuse my brevity.</body></html>