linux : Search in files script

A super linux ability : find files containing certain words.
but typing the command (even remembering it! ) is anoying.
Lets create a quick script to ease the use !

sudo nano /usr/bin/myfind

#!/bin/bash
if [ $# -eq 0 ]
  then
    echo "No arguments supplied"
    exit;
fi
grep -rnw -A1 -B1 './' -e "$1"

Type : myfind aword
to list every file containing « aword » in the current directory and his subfolders (recursive !)

Laisser un commentaire