find
Find is unique in that it can execute based on what is found. This is often what it is used for, even though other tools, like grep can search through text files as well.
Find Files + Specific String
Restrict the search to files in /etc/apache2/ which contain “StartServers” string
sudo find /etc/apache2/ -name "*.*" -print0 | xargs -0 grep "StartServers"
/etc/apache2/mods-available/mpm_worker.conf:# StartServers: initial number of server processes to start
/etc/apache2/mods-available/mpm_worker.conf: StartServers 2
/etc/apache2/mods-available/mpm_prefork.conf:# StartServers: number of server processes to start
/etc/apache2/mods-available/mpm_prefork.conf: StartServers 5
/etc/apache2/mods-available/mpm_event.conf:# StartServers: initial number of server processes to start
/etc/apache2/mods-available/mpm_event.conf: StartServers 2
grep: /etc/apache2/sites-enabled/000-default.conf: No such file or directory
/etc/apache2/mods-enabled/mpm_prefork.conf:# StartServers: number of server processes to start
/etc/apache2/mods-enabled/mpm_prefork.conf: StartServers 5
Find + Find
Find items of type file in the /mnt/foo folder, named “grimoire” anything
find /mnt/foo -type f -name '*grimoire*'
Find items of type directory, named “grimoire” anything, then find things inside of those things
find /mnt/foo -type d -name '*grimoire*' -exec find {} \;
find /mnt/foo -type d -name '*grimoire*' -exec find {} -type f \;
Find + Replace
Starting from current directly, find all items that are files, that end with .markdown, then replace OLD with NEW, case insensitive
find . -type f -name '*.markdown' -exec sed -i 's/OLD/NEW/gI' {} +