search files by content text using find and grep

Image

This post is about a simple task – but I always forget the syntax. Search recursively for files inside the current directory with a special text in the file content.

find . -name "*.*" -print | xargs grep "SEARCHTEXT" --color=auto

This snippet searches for all files of the current directory that match the name parameter *.* (so you could e.g. search for all .css files with -name “*.css”). The result is displayed with grep – using the nice color-highlighting.

This is especially useful for remove access on linux machines or other unix-based devices.