Grepping through subdirectories

April 12, 2007

This is how to grep recursively through subdirectories but only for files that match a specific pattern:

grep -l -r –include=*.htm regex *

The equivalent command with find is:

find . -name ‘*.htm’ -exec grep -l regex \{\} \;

The option after grep is the lowercase letter L, not the number 1). Remove the -l to see the actual matches instead of the file names.


Tomcat on port 80

April 7, 2007

I tried using rinetd to run Tomcat on port 80 but then you do not know the original ip address. Using iptables keeps the original IP address. The magic incantation that worked for me is (each should be a single line):

iptables -t nat -A OUTPUT -d localhost -p tcp –dport 80 -j REDIRECT –to-ports 8080iptables -t nat -A OUTPUT -d dotted.ip.address.here -p tcp –dport 80 -j REDIRECT –to-ports 8080

iptables -t nat -A PREROUTING -d dotted.ip.address.here -p tcp –dport 80 -j REDIRECT –to-ports 8080