linux

How to find all files containing specific text in linux?

Recently, while working on a project, I needed to search if an image I intended to delete was in use anywhere else in the code. There were lot’s of text files to go through and I needed a quick way to tell whether or not it was safe to delete said image. I learned how to use grep, which is a commandline utility for searching plain text files. To find files that contain the text you’re looking for, do the following:

grep -rnw '/path/to/directory' -e "pattern"

Where:

r – recursive
n – show line number
w – only show whole word matches

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s