Find string within files on a Linux Server

This is a very useful bit of code, used to search within files on a Linux server. Replace the . after find to search within a folder.

find . | xargs grep -s "search string" > search.log

This script finds all files at or below current directory, then runs a search within the files.

find . (find all files at or below current directory)
xargs (build and execute commands from standard input, separated by newline)
grep (search within the file for the quoted string), using the -s flag to suppress directory warnings

Leave a Reply