Search for file on Linux using grep and find

Search for files containing a certain text, on my Synology, ignoring warnings like ' Permission denied'

Click to Read More

Just a note for myself... as I always forgot the syntax :/

Using grep only

grep -rnlw '/path/to/somewhere/' -e 'pattern' 2>/dev/null

grep -rnlw 'text' '/path/to/somewhere/' 2>/dev/null

  • -r or -R is recursive,
  • -n is line number, and
  • -w stands for match the whole word.
  • -l (lower-case L) can be added to just give the file name of matching files.

Using find

find '/path/to/somewhere/' -type f -exec grep "text" '{}' \; -print

Leave a Reply

Your email address will not be published. Required fields are marked *