I'm trying to look for a file called Book1.
In my test I'm trying to look for the aforementioned file and in this test, I don't know where that file is located.
I tried find / -iname book1
but there is no output.
How do I find my file called book1 using the command line if I don't know where the file is located?
EDIT:
My scenario is described in more detail below:
- The file extension is unknown
- The exact name (i.e. Capitalized letters, numbers, etc.) is unknown
- The location of the file is unknown
Best Answer
First, an argument to
-iname
is a shell pattern. You can read more about patterns in Bash manual. The gist is that in order forfind
to actually find a file the filename must match the specified pattern. To make a case-insensitive stringbook1
matchBook1.gnumeric
you either have to add*
so it looks like this:or specify the full name:
Second,
-iname
will makefind
ignore the filename case so if you specify-iname book1
it might also findBook1
,bOok1
etc. If you're sure the file you're looking for is calledBook1.gnumeric
then don't use-iname
but-name
, it will be faster:Third, remember about quoting the pattern as said in the other answer.
And last - are you sure that you want to look for the file everywhere on your system? It's possible that the file you're looking for is actually in your
$HOME
directory if you worked on that or downloaded it from somewhere. Again, that may be much faster.EDIT:
I noticed that you edited your question. If you don't know the full filename, capitalization and location indeed you should use something like this:
I also suggest putting
2>/dev/null
at the end of the line to hide all*permission denied*
and other errors that will be present if you invokefind
as a non-root user:And if you're sure that you're looking for a single file, and there is only a single file on your system that match the criteria you can tell
find
to exit after finding the first matching file: