Operating Systems 2019-01-22

Introduction to grep

Master Linux grep command for text searching using patterns, wildcards, and practical techniques for file analysis.

Read in: ja
Introduction to grep

Overview

grep is a command I used casually, so I decided to investigate it more thoroughly.

Basics

grep search-pattern filename

You can use wildcards, so for example, if you want to target all files in the current directory, you can do it like this:

grep "foo" ./*

If you want to include directories under the current directory, use the -r option.

grep -r "foo" ./*

Options

Here are some commonly used options.

-i

-v

-n

-l

-L

-r

-w

Practical Use

grep "foo\|bar" ./*

You need to escape with \.

grep "foo" ./* | grep "bar"

Exclude Specific Directories

grep "foo" ./* --exclude-dir=vendor

References

Tags: Linux grep
Share: 𝕏 Post Facebook Hatena
✏️ View source / Discuss on GitHub
β˜• Support

If you enjoy this blog, consider supporting it. Every bit helps keep it running!


Related Articles