cheatsheets devlog projects

search.md

Grep Shortcut

2022-01-02

A grep snippet so I can do search {directory} {keywords}. Extremely useful as I rarely remember how grep works even though I use it quite a bit.

#!/usr/bin/bash

grep --color=always \
    --exclude="*.min.*" \
    --exclude="*nohup*" \
    --exclude="*tsconfig*" \
    --exclude="package.json" \
    --exclude="package-lock.json" \
    --exclude=".*" \
    --exclude-dir=.git \
    --exclude-dir=node_modules \
    --exclude-dir=logs \
    --exclude-dir=target \
    -RIinT \
    "$2" \
    "./$1" | awk '{$1=$1};1'

Exclude various files and directories.

R - Recursively search directories I - Ignore binary files i - Ignore cases n - Show the line number T - Align the results on tabs so that results aren’t indented

Awk is doing some formatting. Not sure what but something.