70

While having a cygwin installed in windows gives most of unix command, still i was wondering how to search multiple filetypes in one command using windows "find" command.
ie: find . -name *.cpp -o -name *.h -o -name *.java

The above command gives me a list of all cpp, h & java, what will be the equivalent using the windows find?

2 Answers 2

105

This will locate all files with the given extensions in the current working directory and all subdirectories:

dir *.cpp *.h *.java /b/s

See https://technet.microsoft.com/en-us/library/cc755121.aspx for more info on using dir.

15
  • 3
    also this command is not working in windows7 somehow .. or maybe i am wrong. Also i found tree might be better alternative than find in windows.
    – Soumen
    Jun 10, 2011 at 6:58
  • 1
    @Soumen: Then don't say 'windows "find" command', but 'the Windows equivalent to unix's "find" command'. Anyway, updated my answer with something that should be closer to what you want. (If I'm not mistaken, tree doesn't allow you to restrict results to files with specific extensions.)
    – JAB
    Jun 10, 2011 at 14:03
  • 3
    And if you want to emulate the very common find . -name \*.cpp | wc -l *nix command idiom, you can use dir *.cpp /b/s | find /c /v "". See Raymond Chen's post for details.
    – ddevienne
    Apr 21, 2015 at 8:41
  • 1
    How to narrow this down to subdir? find . -name "*Test.php" src
    – ioleo
    Jan 29, 2016 at 11:18
  • 2
    @DrPhil I tracked it down to devblogs.microsoft.com/oldnewthing/20110825-00/?p=9803. Just from the old URL and a little time. You could also have done that :)
    – ddevienne
    Feb 16 at 8:14
-3

findstr /p /s /i .

above command searches for the given text in current directories and sub directories. /n will print the line numbers too.

1
  • 6
    This is similar to grep, not find.
    – Ben Voigt
    Oct 28, 2014 at 21:37

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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