Ubuntu – Finding files in sub directories

findls

Still a newbie. Using a clean machine, purchased from System 76 with Ubuntu 14.04 LTS installed. Got it mid-May of 2014.

Why can't I find files in the current and its subdirectories?

I've tried ls, find , locate, which, and whereis. Even tree | grep which will find them but won't tell me where they are.

Example: In my /home directory I have some *.t files. In some of my directories below home, I have some *.t files. I am having a hard time trying to find them all with one CLI command. Any ideas?

Best Answer

The problem with locate might be an outdated database. locate uses a database to show you result and that database is not updated real-time. So new files are not added to it when created. They will get added when the database is updated.

sudo updatedb

updates it for you manually but this is also done daily by cron on a default Ubuntu. locate is not real-time but very fast. locate accepts wildcards.

locate *.jpg 
/discworld/Downloads/Forbidden-Oasis.jpg
/discworld/Downloads/The-Exalted-Plains.jpg
/discworld/Downloads/The-Fallow-Mire.jpg
/discworld/Downloads/The-Hinterlands.jpg
/discworld/Downloads/The-Storm-Coast.jpg
/discworld/Downloads/The-Western-Approach.jpg

and

locate .t 

should give you results if the database is up to date and there are any files ending with ".t". You can filter the results by adding a | grep Western (the example I show above would show 1 result; the last one would be shown) if you get too many results.


find is real-time and as a result it is slower than locate. find will show an error if you search location you are not allowed to search. The command in comments by @g_p is correct and searches from the current location files ending in ".t".

find . -type f -name "*.t"

which is not intended to find files but to find commands so is the wrong tool. whereis is also not intended to find files but you can use to find the binary, source, and manual page files for a command.

Related Question