Can grep search multiple files?

QuestionsQuestions8 SkillsProUser Account ManagementOct, 03 2025
0177

Yes, grep can search multiple files. You can specify multiple file names as arguments, or use wildcards to search through a group of files. Additionally, you can use the -r (or --recursive) option to search through all files in a directory and its subdirectories.

Examples:

  1. Specifying Multiple Files:

    grep "search_term" file1.txt file2.txt file3.txt
  2. Using Wildcards:

    grep "search_term" *.txt

    This command searches for "search_term" in all .txt files in the current directory.

  3. Recursive Search:

    grep -r "search_term" /path/to/directory

    This command searches for "search_term" in all files within the specified directory and its subdirectories.

Using these methods, grep can efficiently search through multiple files at once.

0 Comments

no data
Be the first to share your comment!