Find files containing specific text using grep command
grep is a command-line utility for searching plain-text data sets for lines that match a regular expression. Its name comes from the ed command g/re/p (globally search a regular expression and print), which has the same effect: doing a global search with the regular expression and printing all matching lines. Grep was originally developed for the Unix operating system, but later available for all Unix-like systems.
grep command syntax
grep "text string to search” directory-path
grep [option] "text string to search” directory-path
grep -r "text string to search” directory-path
grep -r -H "text string to search” directory-path
egrep -R "word-1|word-2” directory-path
egrep -w -R "word-1|word-2” directory-path
root@hackthesec:~# grep "PULSEAUDIO_SYSTEM_START" /etc/default/pulseaudio PULSEAUDIO_SYSTEM_START=1
root@hackthesec:~# grep "PULSEAUDIO_SYSTEM_START" /etc/default/* grep: /etc/default/kdm.d: Is a directory /etc/default/pulseaudio:PULSEAUDIO_SYSTEM_START=1 root@hackthesec:~#
root@hackthesec:~# grep -r "PULSEAUDIO_SYSTEM_START" /etc/default/*
/etc/default/pulseaudio:PULSEAUDIO_SYSTEM_START=1
root@hackthesec:~#
root@hackthesec:~# grep -R "PULSEAUDIO_SYSTEM_START" /etc/default/*
/etc/default/pulseaudio:PULSEAUDIO_SYSTEM_START=1
root@hackthesec:~#
root@hackthesec:~# grep --col 'usb 1-1.4' /var/log/messages
Apr 4 09:14:25 kali kernel: [1191164.780496] usb 1-1.4: new low-speed USB device number 21 using ehci-pci
root@hackthesec:~#
root@hackthesec:~# grep --col -r 'Linux version 3.14-kali1' /var/log/* | cut -d: -f1
/var/log/dmesg
/var/log/dmesg.0
/var/log/installer/syslog
root@hackthesec:~#
root@hackthesec:~# grep -R "PULSEAUDIO_SYSTEM_START" /etc/* 2>/dev/null
/etc/default/pulseaudio:PULSEAUDIO_SYSTEM_START=1
/etc/init.d/pulseaudio:PULSEAUDIO_SYSTEM_START=0
/etc/init.d/pulseaudio:if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
/etc/rc0.d/K01pulseaudio:PULSEAUDIO_SYSTEM_START=0
/etc/rc0.d/K01pulseaudio:if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
/etc/rc1.d/K01pulseaudio:PULSEAUDIO_SYSTEM_START=0
/etc/rc1.d/K01pulseaudio:if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
/etc/rc2.d/S20pulseaudio:PULSEAUDIO_SYSTEM_START=0
/etc/rc2.d/S20pulseaudio:if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
/etc/rc3.d/S20pulseaudio:PULSEAUDIO_SYSTEM_START=0
/etc/rc3.d/S20pulseaudio:if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
/etc/rc4.d/S20pulseaudio:PULSEAUDIO_SYSTEM_START=0
/etc/rc4.d/S20pulseaudio:if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
/etc/rc5.d/S20pulseaudio:PULSEAUDIO_SYSTEM_START=0
/etc/rc5.d/S20pulseaudio:if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
/etc/rc6.d/K01pulseaudio:PULSEAUDIO_SYSTEM_START=0
/etc/rc6.d/K01pulseaudio:if [ "$PULSEAUDIO_SYSTEM_START" != "1" ]; then
root@hackthesec:~#
root@hackthesec:~# grep -r "pulseaudio_system_start" /etc/default/*
root@hackthesec:~#
root@hackthesec:~# grep -i -r "pulseaudio_system_start" /etc/default/*
/etc/default/pulseaudio:PULSEAUDIO_SYSTEM_START=1
root@hackthesec:~#