Menu

Windows FINDSTR Command: Find an Error Code Across Every Log File
📰

Windows FINDSTR Command: Find an Error Code Across Every Log File

DEV Community: beginners·arnostorg·19 days ago
#0phOpcoE
#devtobeginners#devto#dev#findstr#logs
Reading 0:00
15s threshold

Something broke overnight, the app wrote forty log files, and all you have is an error code like ERR-504 . You don't need PowerShell, an editor, or a log tool for the first pass. findstr ships with every Windows install since XP, works in a locked-down cmd.exe , and can tell you which files contain the code, which lines , and whether it's there at all in one command.

This post is the version I actually use: search a whole folder tree, get line numbers, list only file names, avoid the space-separated-words trap, and use the exit code in a batch script.

The one-liner

findstr /s /i /n /l /c:"ERR-504" C:\Logs\*.log

Enter fullscreen mode

Exit fullscreen mode

What each switch does:

/s searches the current folder and every subfolder .

/i ignores case, so err-504 and ERR-504 both match.

/n prints the line number in front of each hit.

/l treats the search text literally (no regex surprises).

/c:"..." searches for the exact string, spaces included.

Output looks like this, one hit per line, with…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.