Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In Linux, How do I display lines that contain a string in a text file, such as:

search "my string"  file_name

How do I make the search case sensitive/insensitive? And how do I also display the line numbers?


share|improve this question
up vote 8 down vote accepted


grep -n "my string" file_name 

will do for your particular query. GREP is by default case sensitive in nature and to make it case insensitive you can add -i option to it. The -n option displays the line numbers. For other myriad options, I recommend

man grep

for more interesting pattern matching capability of GREP.

share|improve this answer
Thanks. How do I also get the line numbers? – alwbtc Jul 22 '12 at 15:07
-n will get you the line number – kaji Jul 22 '12 at 15:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.