0

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 ?

3
  • 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
1

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.

0

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.

-1

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.