Menü schliessen
Created: February 21st 2014
Last updated: May 1st 2020
Categories: Linux
Author: Marcus Fleuti

Linux (bash) find specific file content in all files within a given directory

Tags:  bash,  find,  grep,  Linux,  recursive,  xargs
Donation Section: Background
Monero Badge: QR-Code
Monero Badge: Logo Icon Donate with Monero Badge: Logo Text
82uymVXLkvVbB4c4JpTd1tYm1yj1cKPKR2wqmw3XF8YXKTmY7JrTriP4pVwp2EJYBnCFdXhLq4zfFA6ic7VAWCFX5wfQbCC

1. Search for content within files using regular grep

find ./ -type f -exec grep -Hn "YourContent" {} \;

2. Search for content using the xargs command

find ./ -type f |xargs grep -Hn "abc"

General notes

  • In most situations/directories you won't need the parameter "-type f"
  • For case insensitive search just apply the parameter -i. Examples:
    find ./ -type f -exec grep -Hni "YourContent" {} \;
    find ./ -type f |xargs grep -Hni "abc"