Useful Linux Commands

  • print lines matching a pattern within a directory with its subdirector
    grep(1) -rnw '/path/to/somewhere/' -e "pattern"

    -R, -r, –recursive
    Read all files under each directory, recursively; this is equivalent to the -d recurse option.

    -n, –line-number
    Prefix each line of output with the 1-based line number within its input file. (-n is specified
    by POSIX.)

    -w, –word-regexp
    Select only those lines containing matches that form whole words. The test is that the matching
    substring must either be at the beginning of the line, or preceded by a non-word constituent
    character. Similarly, it must be either at the end of the line or followed by a non-word
    constituent character. Word-constituent characters are letters, digits, and the underscore.

    -e PATTERN, –regexp=PATTERN
    Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a
    pattern beginning with a hyphen (-). (-e is specified by POSIX.)

grep searches the named input FILEs (or standard input if no files are named, or if a single hyphen-minus
(-) is given as file name) for lines containing a match to the given PATTERN. By default, grep prints
the matching lines.

Thanks: https://explainshell.com/