Find all files containing a given string

A quick one-liner to recursively search files for a given text string.

Open up a terminal session and enter the following - replacing "foo" with the text to search for.

find . -exec grep -l "foo" {} \;

You can also limit the search to files with a particular extension (e.g. HTML or CSS). The first form will only return files in the current directory

find *.html -exec grep -l "foo" {} \;

Alternatively you can search recursively while matching filenames using the -name parameter:

find . -name *.html -exec grep -l "foo" {} \;

You can pass other options to find including for example -mtime -1 to specify only files modified within the past day.
You can also replace . with the name of any other folder to search:

find /var/www -name *.html -exec grep -l "foo" {} \;

This will search /var/www recursively for files named *.html and containing foo.

Continue reading

Collaborate in the shell with screen (multiuser)  bash

Screen is a neat little program that allows you to use multiple virtual terminals in a single session on Unix/Linux and Mac. However, it does more than just that. It can also allow you to share your current session on a machine with another user - allowing you to collaboratively … More