On a Linux server, I need to find all files with a certain file extension in the current directory and all sub-directories.
Previously, I have always used the following command:
find . -type f | grep -i *.php
However, it doesn't find hidden files, for example .myhiddenphpfile.php
. The following finds the hidden php
files, but not the non-hidden ones:
find . -type f | grep -i \.*.php
How can I find both the hidden and non-hidden php
files in the same command?
...
It's better to use iname (case insensitive).
I use this find command to search hidden files:
Extracted from: http://www.sysadmit.com/2016/03/linux-ver-archivos-ocultos.html
The issue is grep, not the find (try just
find . -type f
to see what I mean).If you don't quote the
*
then the shell will expand it - before grep even sees its command line arguments; since the shell doesn't find hidden files by default, you'll have issues.The reason it's only finding the hidden file is because the shell has already expanded the
*
and so grep is only matching that one file.