Much faster than find, if you're running the locate service, and it only finds files that existed at the time updatedb last ran (usualy the night befor under the control of a cron job).
You can run updatedb by hand, but that is even slower than the find cletus suggests, and requires root. I sometimes update the database by hand after installing a bunch of new stuff.
As others mentioned, locate is the fast way to find a file. This command uses an pre-compiled index of the file and folder names. This database of names is searched, rather than crawling through your file system.
locate example.filename
To be case-insensitive, add -i.
locate -i eXAmPle.FileName
Update locate database
The database used by locate must be up-to-date. After doing an install or download that may contain your desired file, you must update the locate database.
The locate database will eventually be updated automatically by your FreeBSD system. There is a weekly set of chores that includes this task. These chores are listed in the /etc/periodic/weekly/310.locate script.
The easiest safest way to force the early updating of the locate database is to force the weekly set of chores to be done now.
sudo periodic weekly
Or, you could even force all the regular chores to be done. You might want to do this immediately after setting up a new FreeBSD system.
sudo periodic daily weekly monthly
If using other avenues to update the locate database, you may get a message about being unsafe, revealing the names of all your system’s files to any user on the FreeBSD system. Using the periodic route avoids this problem.
Much faster than
find
, if you're running the locate service, and it only finds files that existed at the timeupdatedb
last ran (usualy the night befor under the control of a cron job).You can run
updatedb
by hand, but that is even slower than thefind
cletus suggests, and requires root. I sometimes update the database by hand after installing a bunch of new stuff.If you've got locate (aka slocate) installed, then
locate runs a cron job every night that reindexes all the files on your machine. It's not always up to date for that reason.
Sometimes you want to find files at a specific directory level. In this case it can be convenient to use shell wildcards:
Obviously this only works if you have a rigid directory structure.
I sometimes do
probably hugely inefficient however.
locate
As others mentioned,
locate
is the fast way to find a file. This command uses an pre-compiled index of the file and folder names. This database of names is searched, rather than crawling through your file system.To be case-insensitive, add
-i
.Update
locate
databaseThe database used by
locate
must be up-to-date. After doing an install or download that may contain your desired file, you must update thelocate
database.The
locate
database will eventually be updated automatically by your FreeBSD system. There is a weekly set of chores that includes this task. These chores are listed in the/etc/periodic/weekly/310.locate
script.The easiest safest way to force the early updating of the
locate
database is to force the weekly set of chores to be done now.Or, you could even force all the regular chores to be done. You might want to do this immediately after setting up a new FreeBSD system.
If using other avenues to update the
locate
database, you may get a message about being unsafe, revealing the names of all your system’s files to any user on the FreeBSD system. Using theperiodic
route avoids this problem.If you have the locate database up-to-date, then just: