grep Patterns and Flags I Use to Search Anything
grep is the first tool I reach for when something is wrong on a server. These patterns and flags cover most of what I need. grep is the Linux tool I use most often. When a service fails, I grep the logs. When a config is wrong, I grep the config files. When I need to find every reference to a function across a codebase, grep finds them. After years of daily use, I have a set of flags and patterns that cover almost every search I perform. Here they are, with the contexts where each one fits. The Flags I Use Every Day The -r flag searches recursively through directories. Without it, grep only searches a single file. With it, grep walks the directory tree and reports the filename and matching line for each hit. I use -r more than any other flag. grep -r 'database_host' /etc/ The -i flag makes the search case-insensitive. I use it when I am not sure of the capitalization, which is common when searching documentation or user-generated content. The -n flag prints the line number with each match, which I need when I am about to edit the…