grep Ignore Case in Linux
-
the
grep
Syntax in Linux -
the
grep
Case Sensitivity in Linux -
the
grep
Case Insensitive With the-i
Option
In this tutorial, we will learn to use grep
documentation to ignore cases in filenames. But first, let’s start with grep
.
Each file is searched for patterns using grep
. Patterns list patterns separated by newlines, and grep
outputs each line that matches a pattern.
Patterns should usually be quoted when using grep
in a shell command. Recursive searches check the working directory if no file is specified, while non-recursive searches read standard input.
the grep
Syntax in Linux
The syntax for the grep
command is given below:
$ grep [OPTIONS] PATTERN [FILE...]
Optional items are shown within square brackets.
- The
OPTIONS
-grep
has several settings that can be used to customize how it behaves. - The
PATTERN
is a pattern you can use to find something. - The
FILE
is the name of one or more input files.
The user who runs the command must have read access to the file to search.
the grep
Case Sensitivity in Linux
The grep
command’s default behavior is case-sensitive. Case-sensitive accepts lowercase letters that differ from uppercase letters.
For example, the pattern THANOS
does not match thanos
, Thanos
, or ThanoS
. The text file looks like this:
$ grep "THANOS" thanos.txt
Output:
THANOS
the grep
Case Insensitive With the -i
Option
The grep
command’s -i
option can perform a case-insensitive search. For a case-insensitive search, the search pattern THANOS
matches Thanos
, ThaNos
, or ThanoS
.
$ grep -i "THANOS" thanos.txt
Output:
THANOS
thanos
Thanos
ThanoS
The ignore-case
option is a more extended variant of the -i
option. As a result, we can use the grep
command with the ignore-case
option for a case-insensitive match.