-4

I have a directory with many sub directories, I want to find a file in this directories so I use this command:

find ./ -name test.php

but this command search just in the top level directory,

how can I search in all sub directories too?

Uwe Plonus
  • 574
  • 3
  • 14
MajAfy
  • 107
  • 2
  • 6
  • 2
    The command you're posting does search all sub directories. What makes you think it doesn't? – Jenny D Jun 10 '13 at 10:07
  • 2
    This should work as expected - what exactly is the problem you are trying to solve. – user9517 Jun 10 '13 at 10:11
  • @MajAfy Can you change the post so it states what it is you want? Just finding where the files are so that you can use a command to find then seem tying the horse behind the wagon. I suspect that you are trying to find them so you can do something in a script with them. However that is a guess since the OP lacks that information. – Hennes Jun 10 '13 at 12:03

3 Answers3

3

The command will you used will search the directories (including all sub-directories) for files named test.php.

It will search subdirectories, assuming you have the rights needed.

However you might want to change -name to -iname so that you can find files regardless of the case. (e.g. also find Test.php, test.PHP or teSt.phP)

You might also want to add -ls or -print. Printing the file location when found is the default for many 'finds', but it is a good habit to explicitly do this.

Examples:

mkdir footest1
cd footest1
touch test.php
touch TesT.pHp
cd ..

find ./ -name test.php -print
./footest1/test.php

find ./ -iname test.php -print
./footest1/test.php
./footest1/TesT.pHp

If you are going to feed the output from find to another program then consider -print0.

Hennes
  • 4,842
  • 1
  • 19
  • 29
0

That should work. Does your user have privileges to cd into and read the sub dirs and the file you want?

Jason Tan
  • 2,752
  • 2
  • 17
  • 24
0

Also you cold try

ls -lR | grep test.php
dr-evil
  • 377
  • 1
  • 5