FreeBSD: How To Find A File (Or Directory)
Written by: Donovan / Last updated: Jan 10, 2023If you’re looking for a file (or directory) in FreeBSD or OpenBSD, there are 3 commands you should know about:
find
whereis
locate
1. find
find
can be used to find a file or directory.
You use it like so:
# File
find / -type f -name "file name"
# Directory
find / -type d -name "directory name"
You can change the /
to any folder you want to start searching in.
2. whereis
The whereis
command is useful for finding the location of a binary.
Say, for example, you want to find the exact location of the ls
binary:
# Command
whereis ls
# Result
/bin/ls
3. locate
Before you can use the locate
command, you’ll need to build its database like so:
doas (or sudo) /usr/libexec/locate.updatedb
You can then find a file or directory like so:
locate filename
This is basically like running find
but it’s a lot faster, since you’ve prebuilt the database. Just beware that running the locate.updatedb
command as root will expose every single file (including in your root folder) on the system to every user.