find file based on its content

On my last post I’ve mentioned tool called Agent Ransack for Windows that has ability to search file based on it’s content (and other criteria such as modification time). On Linux, there’s no need to install additional package/application. There is already a command line tool that will do the trick, i.e. grep.

For example, you want to find all php files in the current folder and its subfolder that contain word “stat

Parameters explanation:
–color=auto : this will made the word ‘stat‘ highlighted
-i : ignore pattern case (case in-sensitive — the pattern is ‘stat’)
-nH : show filename and the line number

grep example output

example output

If you want to add file modification time as the other criterion, you must combine find and grep command.
For example, you want to search all php files in the current folder and its subfolder that contain word ‘stat‘ and the file was last modified within less than one day a go:

Please refer to find man pages for more option about file modification/access/creation time options.

Leave a Reply

%d bloggers like this: