Find files containing string in Ubuntu

Use following command to find all files that contain some specific string.

find . -exec grep -l “string to find” {} \;

“find .” means find from current directory

“-exec” action for find command executes command that follows until “;” is encountered

“grep -l” looks for strings in files and flag “-l” means that display file name instead of matching line

curly brackets “{}”  are replaced on runtime with filename that was found

“\;” means that command to be executed when file is found ends

If you get

find: missing argument to `-exec'

Then you have to add the space between {} and \;

 


Leave a Reply

Your email address will not be published.


*