I am looking for a gratis Windows program to search through a directory tree and find all files containing a given string.

Must have:
- Windows
- Gratis
- must NOT create or rely on any index or other type of database
- for each matched file, show the matching line(s)
- search text files

Nice to have:
- Linux
- show X lines before/after the match
- search within archives (at least ZIP, 7Z and RAR) - search PDF files
- search MS Word files (and Excel, and PowerPoint)
- search Open/Libre Office files
- count of matching files/lines
- use wildcards * and ? in search string
- specify string as regular expression
- click found file to open it
- specify file sizes, dates, etc
- search again for new string within the current search results

Note that Agent Ransack does much of this, but some of the "nice to have" features are not available in the gratis version (nor does it have a Linux version). Does anything else tick more items?


[Update] Ultra File Search is also looking good


[Update++] I really, really, really like SearchMonkey on Linux, so anyone looking for a Linux only solution, check it out. Alas, the Windows version - while it offers wildcards in filenames and shows a preview pane with lines matched - does not let me specify how many lines around the hit I see and does not allow searching with regular expressions :-(

But, AstroGrep is a great match - for Windows (with maybe even a few small extra features). So, that's one for each o/s; alas, not the same one.

That's my personal solution. YMMV

  • 1
    There exist various tools which don't quite meet all of your requirements. Have you tried contacting the developer(s) of these tools and asking them to add the features you want? – tealhill Nov 10 '15 at 3:21

FINDSTR

Windows command terminal has a FINDSTR command which you can use to search for a string in a set of files. There's some documentation which I regularly refer to when I need to use it.

Criteria Matches:

Since it's from MS-DOS, I assume it doesn't use or create an index; it certainly doesn't get any faster if I run the same search over and over.

It handles wildcards and a flavor of regex.

It can print the line number and the line where it found the string. It can also just print out the names of files where the string was found.

Linux has grep, which does the same things.

Criteria Failures:

It can't search within archives by itself, though it could be used in a batch script that extracts archives to a temporary directory when encountered, and cleans up after itself.

I don't think it can search MS Word or PDF documents; it's designed for plaintext rather than binary files.

It doesn't have a feature to display file sizes and created/modified dates, but you could pipe its output into a text file and use that to pull up the files' sizes and dates using another command-line program.

Bonus Features you didn't ask for but might like:

It can use a file to specify which files/directories to search.

It can use a file to specify multiple search strings.

I rarely work on Windows, but sometimes I have to. In those cases I often used File Commander – which is a Norton Commander clone, available cross-platform:

File Commander is a text mode orthodox file manager for Microsoft Windows, OS/2 and Linux operating systems […]. It is an enhanced clone of Norton Commander […]. Functionality has been greatly extended with features such as support for regular expressions in file selection, a powerful editor with undo/redo capabilities, network awareness, etc.

You can find more details on it and download it from its official homepage.

So, how does it meet your requirements?

  • Windows: Yes.
  • Gratis: Shareware. I've never paid anything for the few times I used it.
  • must NOT create or rely on any index or other type of database: No, doesn't.
  • for each matched file, show the matching line(s): This is a question of definition. It gives you a list of matching files, and offers you to open it in an editor or viewer – and there jumps to the matching line.
  • search text files: File Find facility combining wildcard file name filters with file contents scanning. Allows search/replace of text within matching files.

What about your nice-to-haves?

  • Linux: Yes.
  • show X lines before/after the match: Well, shows the entire file and lets you "jump around" – so yes.
  • use wildcards * and ? in search string: Indirectly (use RegEx).
  • specify string as regular expression: Yes.
  • click found file to open it: Well, no. It's a text-based app, so no clicking. Hit Enter instead to go to the file, F3 to open it in the viewer, F4 for the editor :)

Cannot tell you about the other points, as it's quite a while ago since I've last used it. On Linux, I prefer Midnight Commander (similar appearance) – and even on Windows I went using that via Cygwin (MobaXterm makes that easy).

As a side-effect, in both cases you've got a decent text-mode file manager which is highly customizable (user menus, react on certain file extensions, even extensible, integrated editor with syntax highlighting, and more).

  • Thanks, Izyy (+1). Alas, I won't award the answer, as it falls down on "for each matched file, show the matching line(s)", which is a "must have". I want to see all matching lines in an overview, at once. Btw, for Windows, I recommend Total Commander (ghisler.com) for which I paid the shareware fee about 20 years ago (first I ever paid),. I have found nothing to match it on either Windows or Linux. On Linux I use Gnome Commander or Tux Commander, but neither match up - do you know of a better Norton Commander clone? – Mawg Aug 28 '15 at 9:18
  • 1
    I thought so already when reaching that point, but as you've not been 100% clear of that with your question … :) As for TC: I prefer text-based file management, even on Windoze :) – Izzy Aug 28 '15 at 9:22
  • 1
    FAR Manager is a more frequently maintained fork of Norton Commander (same source of File Commander). It has similar features in addition to mouse support, and to being open source with a BSD licence – Tymric Aug 30 '15 at 12:34
  • 1
    That's right, @Timmy (it was shareware a few years ago). I didn't mention it as it isn't available for Linux. As a further note on it: if Linux is no requirement, it's a good choice – and also highly extensible with a ton of plugins. I've used that years ago as well :) – Izzy Aug 30 '15 at 13:36

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.