How can I find all files containing specific text (string) on Linux?

Do the following: grep -rnw ‘/path/to/somewhere/’ -e ‘pattern’ -r or -R is recursive, -n is line number, and -w stands for match the whole word. -l (lower-case L) can be added to just give the file name of matching files. -e is the pattern used during the search Along with these, –exclude, –include, –exclude-dir flags … Read more

Using sed and grep/egrep to search and replace

Use this command: egrep -lRZ “\.jpg|\.png|\.gif” . \ | xargs -0 -l sed -i -e ‘s/\.jpg\|\.gif\|\.png/.bmp/g’ egrep: find matching lines using extended regular expressions -l: only list matching filenames -R: search recursively through all given directories -Z: use \0 as record separator “\.jpg|\.png|\.gif”: match one of the strings “.jpg”, “.gif” or “.png” .: start the … Read more

how do I use the grep –include option for multiple file types?

You can use multiple –include flags. This works for me: grep -r –include=*.html –include=*.php –include=*.htm “pattern” /some/path/ However, you can do as Deruijter suggested. This works for me: grep -r –include=*.{html,php,htm} “pattern” /some/path/ Don’t forget that you can use find and xargs for this sort of thing too: find /some/path/ -name “*.htm*” -or -name “*.php” … Read more

How to search contents of multiple pdf files?

There is pdfgrep, which does exactly what its name suggests. pdfgrep -R ‘a pattern to search recursively from path’ /some/path I’ve used it for simple searches and it worked fine. (There are packages in Debian, Ubuntu and Fedora.) Since version 1.3.0 pdfgrep supports recursive search. This version is available in Ubuntu since Ubuntu 12.10 (Quantal).

grep without showing path/file:line

No need to find. If you are just looking for a pattern within a specific directory, this should suffice: grep -hn FOO /your/path/*.bar Where -h is the parameter to hide the filename, as from man grep: -h, –no-filename Suppress the prefixing of file names on output. This is the default when there is only one … Read more

How can I grep recursively, but only in files with certain extensions?

Just use the –include parameter, like this: grep -inr –include \*.h –include \*.cpp CP_Image ~/path[12345] | mailx -s GREP email@domain.example That should do what you want. To take the explanation from HoldOffHunger’s answer below: grep: command -r: recursively -i: ignore-case -n: each output line is preceded by its relative line number in the file –include … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)