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.
Best Answer
find
can select files on various time conditions:The command lists the files
~
and it's subdirectories; There can be multiple directories.f
: plain file, so a directory like./foo.cpp
is not found (it is of typed
)'*.cpp'
- which needs to be quoted, so the shell does not expand it beforefind
it even sees.-m...
) up to (-
) 5 minutes (-...min
) ago.ls -l
-mmin
selects by modification time in minutes,-mtime
would select by modification time in days.-mmin -5
selects files changed in the last 5 minutes,-mmin 5
selects for changed 5 minutes ago,-mmin +5
for more than 5 minutes-newer otherfile
compares to the age of another file-iname '*.cpp'
would also matchfoo.CPP
andbar.cPp
-ls
shows file details like modification time. To get only filenames, leave it out.That's a short summary, there are many more useful options - see
man find
.