Linux find help

I am trying to find "php.ini". So I do the command:

find / "php.ini" 2>/dev/null

It is giving me thousands of files that do not contain "php.ini". What am I doing wrong?

Your requirements are not clear. The command that you are using is asking for the find utility to look at the root directory, every file in the file hierarchy rooted in the root directory, a file or directory named "php.ini" (and, if "php.ini" is a file of type directory, every file in the file hierarchy rooted in "php.ini") and to print the name of every file it encounters while looking at those files and file hierarchies.

Are you looking for a file named "php.ini"?

Are you looking for a file with a filename that contains the string "php.ini"?

Are you looking for a file with a filename that ends with the string "php.ini"?

Are you looking for a regular file that contains the string "php.ini" somewhere in its contents?

Fully seconding what Don Cragun says, but wildly guessing you are looking for a file, why don't you try again adding the -name test?

What you have asked the find command to do is to list everything under the root directory and everything under the directory php.ini (if that exists)

I suspect that this is not what you want and Don has already given suggestions of what you might want.

To get find to do something else, you will need to do something else. You don't say quite what you want so it's difficult to help. It could be:-

  • Find a file named php.ini
  • Find a file name containing php.ini
  • Find a file containing php.ini
  • Find a file only containing php.ini
  • Find a directory called php.ini
  • Find all files newer than a file called php.ini
  • Find all files of the same size as php.ini
  • Find all pipe files under a directory called php.ini

... to name but a few.

If you are still stuck, let us know what you actually need and we can try to help.

Kind regards,
Robin

This one:

Are you looking for a file named "php.ini"?

find / -name "php.ini" 2>/dev/null 

Is this how you would do these two?

Are you looking for a file with a filename that contains the string "php.ini"?

find / -name "*php.ini*" 2>/dev/null 

Are you looking for a file with a filename that ends with the string "php.ini"?

find / -name "*php.ini" 2>/dev/null 

How would you do this one?

Are you looking for a regular file that contains the string "php.ini" somewhere in its contents?

Yes this worked :).

find / -name "php.ini" 2>/dev/null