How to find a file from any directory
First, an argument to
-iname is a shell pattern. You can read more
about patterns in Bash
gist is that in order for
find to actually find a file the
filename must match the specified pattern. To make a case-insensitive
Book1.gnumeric you either have to add
* so it
looks like this:
find / -iname 'book1*'
or specify the full name:
find / -iname 'Book1.gnumeric'
-iname will make
find ignore the filename case so if you
-iname book1 it might also find
bOok1 etc. If
you're sure the file you're looking for is called
then don't use
-name, it will be faster:
find / -name 'Book1.gnumeric'
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.
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:
find / -iname 'book1*'
I also suggest putting
2>/dev/null at the end of the line to hide
*permission denied* and other errors that will be present if you invoke
find as a non-root user:
find / -iname 'book1*' 2>/dev/null
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:
find / -iname 'book1*' -print -quit 2>/dev/null
You may try the
locate command. It uses a database of filenames to make searching quicker.
To search for all file matching
*book1*, and ignoring case, you could use
locate -i book1
if you want to search for files starting with
book1 you will need to do the wildcard yourself:
locate -i 'book1*'
It is much faster than
find, but is only as up-to-date as the last time the database was refreshed.
If you know you have a file called
book1.something, where the file location, the exact value of
something, and the capitalization pattern of the filename are all unknown:
find / -iname 'book1.*'
If all you know for sure is that the filename contains the word
book, you can generate a likely much larger list with
find / -iname '*book*'
The argument to
-name is a shell glob pattern. From the directory the file is in, compare:
$ ls Book1 ls: cannot access 'Book1': No such file or directory $ ls Book1.* Book1.gnumeric
This represents the kind of search performed by
-iname option simply allows a case-insensitive version of this.