1

I am using linux server and a file is missing and I need to find all the files matching a name MyMissingFile ...how can I issue a command that will do a recrusive search of all the directories under user folder and tell me where the file is
I am not a root user. Thanks

3 Answers 3

3

How about

 cd <userfolder>
 find . -name <filename> -print

BTW, filename could be contain a pattern, and

Thus

 find . -name '*MyMissingFile*' -print
3
  • 4
    -print is unnecessary (it's the default)
    – tylerl
    Aug 26, 2010 at 21:31
  • 1
    cd is unnecessary: find /path/to/dir -name filename Aug 27, 2010 at 1:09
  • 2
    worth mentioning -iname when used the search is NOT case sensitive
    – Radek
    Aug 27, 2010 at 7:01
5

There are several ways to find a file.

The easiest one is probably to use the locate command. This command uses a cache of known files. In order to use it, you need to make sure the cache is up-to-date, using updatedb. In your case, you will have to trust that it is up-to-date since you are not root and cannot update the db. To use locate, type:

$ locate MyMissingFile

If you want only files called exactly "MyMissingFile", use:

$ locate MyMissingFile | grep "/MyMissingFile$"

Now if you know in which directory your file is, you can use find. find does not rely on a cache db, and will scan recursively the directory and print all the files it finds. There are tons of options to filter the found files (see man find to list them), including a -name option to filter on the file name. Use it as such:

$ find $yourdirectory -name MyMissingFile

which will match files whose names are exactly "MyMissingFile". To match names that contain "MyMissingFile", use:

$ find $yourdirectory -name "*MyMissingFile*"

Note that locate is usually much faster than find, since it has the answers in cache, while find needs to read all the files under the given directory.

1
locate -r '/MyMissingFile$'

is more efficient than the suggestions using grep. But not every version of locate accepts -r (though the locate in GNU findutils does).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .