How to find a file from any directory

command linefilesfind

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:

  1. The file extension is unknown
  2. The exact name (i.e. Capitalized letters, numbers, etc.) is unknown
  3. 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 for find to actually find a file the filename must match the specified pattern. To make a case-insensitive string book1 match Book1.gnumeric you either have to add * so it looks like this:

find / -iname 'book1*'

or specify the full name:

find / -iname 'Book1.gnumeric'

Second, -iname will make find ignore the filename case so if you specify -iname book1 it might also find Book1, bOok1 etc. If you're sure the file you're looking for is called Book1.gnumeric then don't use -iname but -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.

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:

find / -iname 'book1*'

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 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
Related Question