-n, --line-number print line number with output lines
-R, -r, --recursive equivalent to --directories=recurse
Un petit exemple :
Je recherche le mot
alonso dans le répertoire
/home/tetsumaki/allons-y
alonso ce trouve sur la ligne 2 du fichier /home/tetsumaki/allons-y/test.h
sur la ligne 5 du fichier /home/tetsumaki/allons-y/test/test2.h
Recherche dans le répertoire :
[tetsumaki@tetsu-arch ~]$ grep -rn "alonso" "/home/tetsumaki/allons-y/"
/home/tetsumaki/allons-y/test.h:2:alonso
/home/tetsumaki/allons-y/test/test2.h:5:alonso
Ou si je me trouve dans le répertoire dans lequel je veux rechercher :
[tetsumaki@tetsu-arch allons-y]$ cd ~/allons-y/
[tetsumaki@tetsu-arch allons-y]$ grep -rn "alonso" .
./test.h:2:alonso
./test/test2.h:5:alonso
Si je veux rechercher que sur les fichiers ayant l'extension ".h" :
[tetsumaki@tetsu-arch allons-y]$ grep -rn --include="*.h" "alonso" "/home/tetsumaki/allons-y/"
/home/tetsumaki/allons-y/test.h:2:alonso
/home/tetsumaki/allons-y/test/test2.h:5:alonso