Use grep to search Linux files and directories smarter

Grep filtering data
(Image credit: OpenClipArt / Pexels)

You’re looking for that one file, the one that contains the all important information for your next meeting. Do you manually search all of your files? That will take time. Instead we use a little Linux command line magic. Grep is a pattern matching command that we can use to search inside files and directories for specific text. Grep is commonly used with the output of one command, piped to be the input of the grep command. For example we can search inside a file for a specific string of text using the less command, and pipe the output to grep.

In this how-to we will use the grep command and commonly added arguments to search for specific strings of data within files. We’ll begin by setting up a small directory of test files as searching an entire filesystem can take some time and create a lot of results.

Latest Videos FromTom's Hardware
Jo Hinchliffe
Contributing Writer

Jo Hinchliffe is a UK-based freelance writer for Tom's Hardware US. His writing is focused on tutorials for the Linux command line. From PCBs to rowing boats to rockets, Jo tries wherever possible to integrate open source hardware and software into his projects. As such he is a keen Linux user, has authored a book on FreeCAD the open source 3D modeling software, and has published designs and tutorials across a wide range of makes.

With contributions from