Grep Command event to List exclusively Filenames alongside Matching String inward Linux

The grep ascendency from Linux is i of the powerful commands to find files containing about text, but when y'all purpose grep it non alone impress the file elevate but also the describe of piece of occupation which is containing the matching text. This is ok for most of the situations but sometimes y'all alone desire to grep to demonstrate filename as well as describe of piece of occupation as well as non the matching text e.g. when y'all are searching for about configuration e.g. database hostname across all configuration files inwards your application host. Since many files comprise the database references, it's possible that y'all powerfulness acquire a lot of information on output, thus if y'all are alone interested inwards all the files containing matching text, y'all tin purpose grep -l option. This choice of grep alone shows filenames which comprise matching text.


Here is what the grep -l ascendency option does (from UNIX standard):

-l
(The alphabetic lineament ell.) Write alone the names of files containing selected
lines to touchstone output. Pathnames are written i time per file searched.
If the touchstone input is searched, a pathname of (standard input) will
be written, inwards the POSIX locale. In other locales, the touchstone input may be
replaced past times something to a greater extent than appropriate inwards those locales.

as well as this is the explanation of grep -l ascendency from grep homo page:

-l, --files-with-matches
Suppress normal output; instead, impress the elevate of each input
file from which output would commonly convey been printed. The
scanning volition halt on the outset match. (-l is specified by
POSIX.)


This choice is frequently used alongside grep -iR, which recursively search for files containing matching text inwards sub-directories equally well. The grep -i is for instance insensitive search. I frequently purpose grep -iRl to impress all the files across directories containing about matching text e.g. hostname or about configuration parameter.

When y'all commonly search without grep -l it prints all files alongside matching text equally good equally shown inwards the next example:


$ grep -iR Intel * 2015/jan/cpu.txt:Intel i7 is best CPU 2015/motherboard.txt:Intel Motherboard is best y'all should ever purchase that. hardware.txt:Intel Corei7

This choice impress all the files alongside a sum path containing matching text equally shown below:

$ grep -iRl Intel *   2015/jan/cpu.txt   2015/motherboard.txt   hardware.txt


Btw, the path printed is the relative path from electrical flow directory as well as non the absolute path from the root or (/).


Here is the screenshot of grep ascendency examples to listing alone filenames alongside matching String inwards Linux:

 The grep ascendency from Linux is i of the powerful commands to  Grep Command instance to List alone Filenames alongside Matching String inwards Linux














That's all nigh the grep ascendency instance to impress filenames containing matching String. You convey also learned how to combine grep -l alongside grep -i as well as grep -R to recursively search for all files containing about matching text. You tin only run this ascendency from a transcend marking directory e.g. habitation or / directory or may endure a top-level directory of your application e.g. /home/appuser/app directory. It's i of the powerful tools to honour out dependencies spell migrating from i host to about other host.

Further Reading
How Linux Works: What Every SuperUser should know
Linux Command Line Interface (CLI) Fundamentals
Practical Guide to Essential Linux Commands
10 Example of wrap ascendency inwards Linux
How to honour all procedure listening on a port?
10 Examples of lsof ascendency inwards Linux

Thanks a lot for reading this far. If y'all similar this instance of grep ascendency to demonstrate alone filenames without matching text as well as then delight part alongside your friends as well as colleagues. If y'all convey whatever inquiry or feedback as well as then delight drib a note.

Subscribe to receive free email updates:

0 Response to "Grep Command event to List exclusively Filenames alongside Matching String inward Linux"

Posting Komentar