grep – common commands

The command-line tool to search for specific words is typically grep. Here’s how you can use it:

Basic Syntax


grep "search_term" file_name

Examples

  1. Search for a specific word in a file:

    
    grep "proxy" /etc/nginx/nginx.conf
    
  2. Search recursively in a directory:

    
    grep -r "proxy" /path/to/directory
    
  3. Search with line numbers:

    
    grep -n "proxy" file_name
    
  4. Ignore case sensitivity:

    
    grep -i "proxy" file_name
    
  5. Show only matching filenames:

    
    grep -l "proxy" /path/to/directory/*
    

For Large Outputs: Combine with less or more

To make results easier to read:


grep "proxy" file_name | less
Scroll to Top