Grep Ascendency Event Inwards Linux - How To Search All Files Matching Specific Text
One of the most mutual business spell working inwards programming projects is finding files containing to a greater extent than or less specific text e.g. yous accept your application deployed inwards Linux server in addition to yous are migrating your database from 1 server to another. Now, yous desire to file all config files in addition to scripts which are referencing your erstwhile database using the hostname or IP address, thus that yous tin sack supersede them alongside an alias. Well, yous should ever purpose an alias to connect to the database or whatever other system, but sometimes it happens yous accept to purpose hostname. Anyway, how create yous honor all those files containing hostname inwards your Linux machine? Well, the grep ascendency is hither to assist you.
The grep command allows yous to scan files to honor whatever matching text in addition to yous tin sack purpose the recursive selection of grep ascendency to honor all files containing a reference to your erstwhile database hostnames, or specific text inwards general.
You tin sack combine recursive selection alongside ignore illustration selection (-i) to honor a specific text similar hostname by ignoring illustration inwards your config files in addition to scripts.
This is the ascendency I ofttimes purpose to search all files inwards unlike sub-directories for finding reference to a specific text e.g. a hostname which is going to decommission or needs to endure migrated:
The -R selection volition recursively search files inwards sub-directories starting from the electrical flow directory in addition to -i volition search for the text you're render ignoring case.
Btw, if yous are non familiar alongside basic Linux commands similar grep, find, chmod etc thus I advise yous to outset acquire through a primal course of education like Linux Command Line Basics on Udemy. This volition assist yous to acquire to a greater extent than inwards a curt time.
Here is an illustration of the recursive search alongside grep ascendency which prints both file in addition to matching text in addition to exclusively file names:
If yous also desire to search for the whole word, instead of merely matching a business office of the text, thus yous drive add together selection -w, which matches the whole give-and-take like
volition search for exact "-Xms" text inwards all files, it is could to honor the scripts where yous are specifying your JVM arguments.
You tin sack also purpose options similar --exclude, --include, --exclude-dir, in addition to --include-dir for to a greater extent than efficient in addition to fast searching. For example, the next ascendency volition exclusively search for text inwards Java files:
You tin sack fifty-fifty purpose the regular expression to render for a to a greater extent than sophisticated search similar the next ascendency volition search for specified text on .c in addition to .h files
This ascendency volition exclude searching all the files ending alongside .svn extension:
As I accept said before, It's non merely of import to acquire novel commands but also novel options of the ascendency yous are familiar alongside to brand the most of Linux power. If yous desire to ameliorate your Linux skills I advise yous acquire through
2) The grep -w is used for give-and-take search i.e. it volition fit to the exact word
3) The grep -i is used for ignoring illustration search e..g it volition fit to "Java", "JAVA", "javA" in addition to other variants.
4) The grep --include is used to search exclusively for surely types of files.
5) The grep --exclude is used to exclude non-interesting files e.g. log files or .svn files.
That's all nigh how to search for matching text inwards all files inwards UNIX in addition to Linux. This ascendency is real powerful in addition to 1 of the useful tool to honor out files referencing right away hostnames instead of aliases. They are real useful for host migrations in addition to database migration. You tin sack fifty-fifty purpose them spell troubleshooting issues.
Further Learning
Linux Command Line Basics
example)10 Example of tar commands inwards Unix (example) 5 Example of kill commands inwards Unix in addition to Linux (example) VI Editor examples in addition to tips for beginners (example) How to purpose the netstat ascendency to honor which procedure is listening on a port? (example) How does nslookup ascendency travel inwards UNIX? (answer) 10 examples of lsof ascendency inwards Linux? (examples) 10 books to acquire essential commands of Linux or UNIX? (list) How Linux works? What Every SuperUser should know? (book) 10 Examples of cURL ascendency inwards Linux? (examples) How to purpose the CUT ascendency inwards Linux (tutorial) How to acquire out from the telnet ascendency inwards UNIX? (example) How to post HTTP asking to telephone phone a spider web service from the ascendency describe inwards Linux? (example)
Thanks for reading this article thus far. If yous similar this article thus delight portion alongside your friends in addition to colleagues. If yous accept whatever inquiry or feedback thus delight driblet a comment.
P. S. - If yous are looking to a greater extent than or less costless courses to acquire or ameliorate your Linux skills yous should banking enterprise check out this listing of Free Linux Courses for Programmers in addition to Developers.
The grep command allows yous to scan files to honor whatever matching text in addition to yous tin sack purpose the recursive selection of grep ascendency to honor all files containing a reference to your erstwhile database hostnames, or specific text inwards general.
You tin sack combine recursive selection alongside ignore illustration selection (-i) to honor a specific text similar hostname by ignoring illustration inwards your config files in addition to scripts.
This is the ascendency I ofttimes purpose to search all files inwards unlike sub-directories for finding reference to a specific text e.g. a hostname which is going to decommission or needs to endure migrated:
$ grep -iR text *
The -R selection volition recursively search files inwards sub-directories starting from the electrical flow directory in addition to -i volition search for the text you're render ignoring case.
Btw, if yous are non familiar alongside basic Linux commands similar grep, find, chmod etc thus I advise yous to outset acquire through a primal course of education like Linux Command Line Basics on Udemy. This volition assist yous to acquire to a greater extent than inwards a curt time.
The grep ascendency to honor all files containing specific text inwards Linux
By default grep volition impress both the matching text equally good equally the lift of the file containing matching text, if yous are merely interested inwards file names thus yous tin sack also purpose the grep ascendency alongside selection -l equally shown below:$ grep -iRl text *
Here is an illustration of the recursive search alongside grep ascendency which prints both file in addition to matching text in addition to exclusively file names:
If yous also desire to search for the whole word, instead of merely matching a business office of the text, thus yous drive add together selection -w, which matches the whole give-and-take like
$grep -iRlw '-Xms' *
volition search for exact "-Xms" text inwards all files, it is could to honor the scripts where yous are specifying your JVM arguments.
You tin sack also purpose options similar --exclude, --include, --exclude-dir, in addition to --include-dir for to a greater extent than efficient in addition to fast searching. For example, the next ascendency volition exclusively search for text inwards Java files:
$ grep --include=\*.java -iRw text *
You tin sack fifty-fifty purpose the regular expression to render for a to a greater extent than sophisticated search similar the next ascendency volition search for specified text on .c in addition to .h files
$ grep --include=\*.{c,h} -iRw text *
This ascendency volition exclude searching all the files ending alongside .svn extension:
$ grep --exclude=*.svn -iRw '/path/to/file/' -e "pattern"
As I accept said before, It's non merely of import to acquire novel commands but also novel options of the ascendency yous are familiar alongside to brand the most of Linux power. If yous desire to ameliorate your Linux skills I advise yous acquire through
Important Points to Remember
1) The grep -r or -R selection is used for recursive search2) The grep -w is used for give-and-take search i.e. it volition fit to the exact word
3) The grep -i is used for ignoring illustration search e..g it volition fit to "Java", "JAVA", "javA" in addition to other variants.
4) The grep --include is used to search exclusively for surely types of files.
5) The grep --exclude is used to exclude non-interesting files e.g. log files or .svn files.
That's all nigh how to search for matching text inwards all files inwards UNIX in addition to Linux. This ascendency is real powerful in addition to 1 of the useful tool to honor out files referencing right away hostnames instead of aliases. They are real useful for host migrations in addition to database migration. You tin sack fifty-fifty purpose them spell troubleshooting issues.
Further Learning
Linux Command Line Basics
example)
Thanks for reading this article thus far. If yous similar this article thus delight portion alongside your friends in addition to colleagues. If yous accept whatever inquiry or feedback thus delight driblet a comment.
P. S. - If yous are looking to a greater extent than or less costless courses to acquire or ameliorate your Linux skills yous should banking enterprise check out this listing of Free Linux Courses for Programmers in addition to Developers.
0 Response to "Grep Ascendency Event Inwards Linux - How To Search All Files Matching Specific Text"
Post a Comment