so I'm in the main folder for my web hosts, trying to find a file using find. I couldn't find it - it was listed as no such file or directory - and I thought maybe it isn't anywhere.

However the following command doesn't work either:

find index.php

which is wrong cause there are a gazillion of them. Why is find not working? Is there a better command to use?

  • 1
    find /some/dir -name index.php – thrig Sep 7 '15 at 16:06
  • It is generally important to include any output or error message produced. In your case it would have been either index.php or find: `index.php': No such file or directory depending on whether or not there was an index.php in your current directory. – roaima Sep 7 '15 at 19:51
  • I think it would really help if you could provide some output when you type a command that is failing. – VaTo Sep 7 '15 at 20:55
  • @Victor, I had a similar problem, FWIW even passing debug flags like -D stat to find produces no output if find works correctly, finding no matches, but in an unexpected way. – pbhj Oct 17 '16 at 13:44

The syntax of find is not like what you have written, please read the manual page man find to get detailed idea.

For example if you want to find files named index.php on the current directory and all the sub directories under it, you can use:

find . -name index.php -type f 

If you want to search for files having names say findex.php, index.phpfoo, index.php you need to use:

find . -name '*index.php*' -type f 

* is a glob pattern meaning zero or more characters.

On the other hand if you want to look in the current directory only :

find . -maxdepth 1 -name '*index.php*' -type f 
  • 1
    find index.php works on my debian jessie. – Ortomala Lokni Sep 7 '15 at 20:05
  • 3
    @OrtomalaLokni That only lists index.php in the current directory if present, it doesn't look in subdirectories. – Gilles 'SO- stop being evil' Sep 7 '15 at 21:40
  • yours is the most concise explanation and example combo. Thanks – Oliver Williams Sep 8 '15 at 15:07
  • The man page for find (on my current Ubuntu install "find (GNU findutils) 4.7.0-git") says that putting the -name first will reduce resource usage as otherwise it checks every object to see if it is a file, then checks the name. So, minor modification find . -name index.php -type f to speed things up a little. – pbhj Oct 17 '16 at 13:31

I had the same problem using find from findutils 4.7.0-git. If I do find . -maxdepth 12 -name '*' -type f then despite having a million files in the below tree no files are returned except those in the current dir. The problem for me was that the dirs below were links, so I needed to do:

find -L . -maxdepth 12 -name '*' -type f

The -L ensures that any links are followed (used to be --follow but that was deprecated).

  • My find command was missing dirs that I knew existed and it turned out they were links. Thanks! – emhohensee Jan 17 at 15:27

Look into the manage of find. There are multiple usage. For example: Find .| grep "Index.php" Or find . -name Xyz.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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