Thursday, October 30, 2014

Thursday, October 2, 2014

grep in a bunch of files

I always have to look this up so I'm posting a note to myself here. To grep through all the files in a directory, recursively, and only get back a list of the files containing the string, do:

tomcat@merchant101 $ grep -lr "import" .
./cleanup/rpp_archive/rpp_backup_2010-01-11.sql

Found this in this blog.

Friday, September 5, 2014

Avoid error messages with `find` in *nix

Very useful comment on StackOverflow about how to get rid of error messages that come up when you use `find`.
You do not need sudo to run find for generally-accessible commands. If you don't want to see the error messages about inaccessible directories, get rid of the messages rather than using root privs unnecessarily. Using sudo all the time is a bad habit. Redirect stderr to /dev/null, like this:
find / -name java 2> /dev/null

Walter Underwood on SO