0

I want to find in the system a file, and I know part name of it. How could I do that? I tried unsuccessfully the command:

find / "*partname*"

The problem is probably very easy however I cannot find a decent tutorial on searching files in linux. Such one that explains searching in whole system files, in subfolders, recursively, for part of specific expression(s) or excluding. Please tell me what command solves my problem and if you know a good tutorial so that I can understand how to use various parameters for searching, post a link. Thank you so much.

beginh
  • 111

2 Answers2

2

Use the -name operator, or -iname if you want to ignore case.

find / -name "*partname*"

Also, unless your file is very deep in a nested hierarchy, you might limit the depth of your search (note this operator must come before any others):

find / -maxdepth 4 -name "*partname*"

-maxdepth 4 is enough most of the time, and I don't think I've ever needed more than -maxdepth 5. I don't bother with these when I'm searching a small directory (e.g. /tmp) but for searching / it becomes important.

You also may want to check out locate, but be aware that its results are cached, so you can't rely on it accurately reflecting what is on your system. For a quick hint about probable location it is quite handy, e.g. just try locate partname and then verify the results with ls -l /path/reported/by/locate/of/your/file

Wildcard
  • 36,499
  • Pretty sure searching deeper than -maxdepth 5 is needed often: like for finding your example file /path/reported/by/locate/of/your/file . – Volker Siegel Aug 16 '16 at 12:03
1

The command you are looking for is:

find / -name "*partname*"

find searches by default recursively through subfolders.

Here is the first result on google for a find tutorial.

If you want to know all the details about find, just type the following to get to the manpage:

man find

exit by pressing q

search through the page with /searchterm

rda
  • 941