viernes, 14 de junio de 2019

How can I find some text in the files of this directory?

Well most of us used to use grep in a pipe with other commands like netstat, ss, ps, etc., but grep is a very powerful tool and for instance could help you to locate text in the files of a directory.
Use:

$ grep -iR "text-to-find" *

The parameter -i is for no case sensitive search and -R is for recursive search.
As a result you can find a list of your files that contains the text and the line containing it.

See and example:

$ cd $TOMCAT_HOME
$ grep -iR "org.apache.tomcat" *
...
conf/catalina.properties:org.apache.naming.resources.,org.apache.tomcat.
conf/catalina.properties:org.apache.jasper.,org.apache.naming.,org.apache.tomcat.
...

The grep command syntax is the following:

grep [OPTIONS] PATTERN [FILE...]

Where the options are:

-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-e exp : Specifies expression with this option. Can use multiple times.
-f file : Takes patterns from file, one per line.
-E : Treats pattern as an extended regular expression (ERE)
-w : Match whole word
-o : Print only the matched parts of a matching line,

No hay comentarios:

Publicar un comentario

How to save a remote server SSL certificate locally as a file?

I found this answer following answer on StackExcahnge and it works perfect. Enjoy! "A quick method to get the certificate pulled and...