This question already has an answer here:

How can search for a file in ubuntu os with grep command ?

Let's say, I want to find CMakeList.txt, how to write grep command to find the existence of this file ?

marked as duplicate by Gilles, don_crissti, Kusalananda, Jeff Schaller, GAD3R Jan 16 '17 at 0:10

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

migrated from stackoverflow.com Jan 15 '17 at 11:26

This question came from our site for professional and enthusiast programmers.

  • You mean to say you want to recursively search down directories for this file? – nu11p01n73R Jan 14 '17 at 5:33
  • 2
    find command exist for such purpose – Vikas Sachdeva Jan 14 '17 at 5:38
  • 1
    linux.die.net/man/1/find – Stephen Rauch Jan 14 '17 at 5:39

grep is not the right tool meant for this, use find with -name to specify the file name you want to get,

find . -type f -name "CMakeList.txt" -print

The above command searches for the file recursively from the current folder and all the sub-directories below.


If this is on a standard Linux installation, you might also try

locate CMakeFile.txt

If it is correctly installed, locate uses a cached index and is often much faster than a find from root directory.


Go into root directory, or a folder that you know your file is in, then

dir "CMakeFile.txt"

Will find it and its location. Works for me, at least.

Not the answer you're looking for? Browse other questions tagged or ask your own question.