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
How about
cd <userfolder>
find . -name <filename> -print
BTW, filename could be contain a pattern, and
Thus
find . -name '*MyMissingFile*' -print
-
4
-
1
-
2
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.
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).