Typical Unix/Linux recursive search commands

The Typical one is – to find the files with some pattern recursively in a given directory.

$ find path/to/dir -name "*.html"

You can replace the “*.html” to your own filename pattern.

Another one is, in addition to above I need the text lines inside those files starting with letter t.

$ find path/to/dir -name "*.html" -exec grep "^t" {} ;

Another version with output filename plus greped text content is

$ find path/to/dir -name "*.html" | xargs grep "^t";

-exec and xargs are the two helped commands to extend the main command functionality.

Leave a Reply

Your email address will not be published. Required fields are marked *