Searching file contents
Stay organized with collections
Save and categorize content based on your preferences.
By default, a query searches both the file path and the content. You can
restrict your search to just the contents of a file by using the
content
filter. For example, the following query looks
for the term main
in the contents of all Java files. It does not search for
instances where a path contains the term main
.
lang:java content:main
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2023-10-03 UTC.
[null,null,["Last updated 2023-10-03 UTC."],[[["\u003cp\u003eThe default search includes both file paths and file content.\u003c/p\u003e\n"],["\u003cp\u003eFor content-only searches, use the \u003ccode\u003econtent\u003c/code\u003e filter, like \u003ccode\u003econtent:main\u003c/code\u003e to find "main" within Java files.\u003c/p\u003e\n"],["\u003cp\u003eThis approach avoids irrelevant results from file paths containing the search term.\u003c/p\u003e\n"]]],[],null,["# Searching file contents\n\nBy default, a query searches both the file path and the content. You can\nrestrict your search to just the contents of a file by using the\n[`content`](../reference#filters) filter. For example, the following query looks\nfor the term `main` in the contents of all Java files. It does not search for\ninstances where a path contains the term `main`. \n\n lang:java content:main"]]