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?
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?
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
.
That should work. Does your user have privileges to cd into and read the sub dirs and the file you want?