Find a file with exact name without using wildcard

I have been using Ubuntu for abuot 2 weeks and and still frustrated with simple file operations.

I want to find a file called 9.jpg. Every internal command and 3rd party program I have tried, gives me 99.jpg, 999.jpg, "lovepotion number9.jpg" and a zillion other similar ones.

How do you search for an EXACT file name WITHOUT wildcards?

This is only my most recent frustration. I'm obviously missing something basic. good tutorial anywhere?


How do you search for an EXACT file name WITHOUT wildcards?

To search an exact file without wildcard use find command.

  1. Open a terminal by Pressing Ctrl+Alt+T

  2. Type the command and hit Enter

    find / -name 9.jpg
    

If you want to search in your home folder only, use ~/ instead of / and so on. Replace / with the directory name you want to search in them. If you want to search in current directory and all directories withing it, use ./ in place of /.

  • For getting help on Learning Linux filesystem, see this page
  • Also see this very helpful guide to become familiar with Linux system, especially with Debian and it's derivatives like Ubuntu.

locate /9.jpg

Note the / - without it you'll just find every file ending in 9.jpg. Technically though, it searches for file paths with it as a substring on all of the drives, which includes 9.jpg.png, so this works better with files that have file extensions - a file named log using /log will show you every file in /var/log/.


The search in nautilus (the file manager thingy) is, by design, limited to a simple wildcard-like option. If you need something more sophisticated, you can either go for the GUI or the command line.

GUI: install the package gnome-search-tool, either through the software center or by typing

 sudo apt-get install gnome-search-tool

Run it (it is called "search for files"). Leave the main entry empty, and add a search option called "Name matches regular expression". In the new text field, type ^9.jpg (the ^ at the beginning matches the beginning of a string in a regular expression).

enter image description here

As for command line, the find utility will give you the precise answer:

 find . -name '9.jpg'

Consider this: files "999.jpg" and "9.jpg" in the directory t/:

$ ls t
99.jpg  9.jpg
$ find . -name '9.jpg'
./t/9.jpg
$ find . -name '*9.jpg'
./t/99.jpg
./t/9.jpg
$

I hope that this is clear.