Recursive Grep Command and Find Command in Linux

Search and Play in Linux

Rishab Batra
1 min readJul 7, 2022

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.jar
Output 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

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Rishab Batra
Rishab Batra

No responses yet

Write a response