Recursive Grep Command and Find Command in Linux
Search and Play in Linux
1] To find name of files with path recursively containing the particular string use below command:
$ grep -nr -e “kafka-clients”
Will show all the files inside subdirectories containing kafka-clients with line number also.
Output:
listlogsWithClasspath:14461:OUTPUT>/classpath/kafka-clients-3.2.0.jartesting classpath
logsWithClasspath:15938:OUTPUT>/classpath/kafka-clients-3.2.0.jartesting classpath
logsWithJson:15938:OUTPUT>/classpath/kafka-clients-3.2.0.jartesting classpath
Clarification:
grep -r "anything" /
(recursively grep all directories and subdirectories)
grep -r "anything" .
(recursively grep these directories and subdirectories)
n will show you line number also where this kafka_clients is present in the file
2]If you want to search any pattern (spark) in specific file logsWithClasspath
Use below command:
$ grep -n -e “spark” logsWithClasspathOutput will be like below:
13691:OUTPUT>spark.executor.instances=10
13698:OUTPUT>spark/target/test-classestesting classpath
3] List down file in linux
To list all Kafka Files inside directory use below command:
find . -name *Kafka*Output:
classpath/kafka_2.12–2.8.1.jar
classpath/kafka-clients-2.8.1.jarOutput will be like below:./../../../../thirdparty/kafka
classpath/kafka_2.12-2.8.1.jar
classpath/kafka-clients-2.8.1.jar
References Used: https://stackoverflow.com/questions/1987926/how-do-i-recursively-grep-all-directories-and-subdirectories