You need a file and you have no idea where it is
You renamed a script, or a service failed to start because a config file vanished, and now you are staring at a terminal trying to recall where that one .conf file lives. You know the filename, or maybe just a fragment of it, but the directory structure is a maze. You need to find it now.
Fedora provides two tools for this job. find walks the filesystem in real time and checks every inode. It is accurate and permission-aware. It is also slow if you point it at the wrong place. locate queries a pre-built database file. It returns results instantly. It can also return stale paths for files that were moved or deleted hours ago.
The choice depends on whether you need absolute accuracy or instant speed. Understanding the trade-off prevents you from wasting time scanning / with find or trusting a ghost path from locate.
The trade-off: accuracy versus speed
Think of find like walking every room in a house and checking every drawer. You will find exactly what is there right now. You will also take a long time, and you might get locked out of a room if you lack the key.
Think of locate like checking an index card catalog in the basement. The catalog lists every item in the house. You can find a match in seconds. The catch is that someone has to update the catalog. If you moved a book yesterday and the catalog hasn't been updated, the card still points to the old shelf.
find reads the filesystem directly. It respects permissions. If you run it as a normal user, it stops at directories you cannot read. If you run it as root, it sees everything. locate reads /var/lib/mlocate/mlocate.db. The database is built by updatedb, which runs periodically via cron or a systemd timer. The database also respects permissions at build time. mlocate will not list files that the user running updatedb cannot read, which keeps sensitive paths out of the database.
Using find for real-time precision
Use find when you need to know what exists right now. Use it when you must filter by permissions, size, modification time, or owner.
Here is how to search for a specific filename starting from your home directory while ignoring directories and symlinks.
# Start search in /home to avoid permission noise in system directories.
# -name matches the filename pattern. Quotes protect wildcards from shell expansion.
# -type f restricts results to regular files, ignoring directories and symlinks.
find /home -name 'config.yaml' -type f
The -type f flag is essential. Without it, find returns directories named config.yaml and symlinks pointing to config.yaml. Most users only want the file itself.
Case sensitivity matters. -name is case-sensitive. If you are unsure about the casing, use -iname.
# -iname matches the filename regardless of case.
# This finds config.yaml, Config.yaml, CONFIG.YAML, and so on.
# Use this when the source of the file used mixed casing.
find /home -iname 'config.yaml' -type f
Sometimes you need to match the path, not just the name. -name only checks the basename. -path checks the full relative path from the search root.
# -path matches the full relative path from the search root.
# This finds ssh configs even if nested deep inside /etc.
# Combine with -name to filter the final filename component.
find /etc -path '*/ssh/*' -name '*.conf'
find can also take action on results. The -exec flag runs a command for every match. The -delete flag removes files directly.
# -mtime +7 matches files modified more than 7 days ago.
# -delete removes the file. This is safer and faster than -exec rm.
# Be careful. -delete does not prompt. Test without -delete first.
find /tmp -type f -mtime +7 -delete
Run find with -type f first. Half the noise in results comes from directories matching the name.
Advanced find patterns and actions
You can combine predicates with -a (and), -o (or), and ! (not). Parentheses group expressions. You must escape parentheses for the shell.
# Find files modified in the last 24 hours that are larger than 100MB.
# -mtime -1 matches files modified less than 1 day ago.
# -size +100M matches files strictly larger than 100 megabytes.
# Parentheses group the conditions. Backslashes escape them for bash.
find /var/log -type f \( -mtime -1 -a -size +100M \)
Performance degrades quickly if you search too broadly. find / -name '*.log' can take minutes and hammer the disk. Always narrow the scope. If you suspect the file is in /etc, start there. If you are hunting for a package file, use rpm -ql or dnf provides instead. Those tools query the RPM database and are faster than scanning the filesystem.
Convention aside: Fedora uses mlocate for the locate command. The package is mlocate. The database updater is updatedb. Do not confuse mlocate with plocate, which is a faster alternative available in some repos but not the Fedora default. Stick with mlocate unless you have a specific reason to switch.
Using locate for instant lookups
Use locate when you need results instantly and the file likely exists in the database. Use it when you are searching for a partial name across the entire system and speed matters more than freshness.
Here is how to query the database for a filename.
# Queries /var/lib/mlocate/mlocate.db for matches.
# Returns all paths containing the string 'config.yaml'.
# Results are instant but may be outdated if updatedb has not run.
locate config.yaml
locate treats the argument as a substring match by default. locate config returns config.yaml, my-config, and /etc/NetworkManager/conf.d/. This is useful for broad searches but can produce noise.
Use -r to enable extended regular expressions. This gives you precise control over the match.
# -r enables extended regular expressions for the pattern.
# This matches files ending exactly in config.yaml.
# Use this to avoid partial matches in directory names.
locate -r 'config\.yaml$'
If locate returns no results for a file you know exists, the database is stale. The file was created or moved after the last database update.
# Force an update of the mlocate database.
# This runs updatedb as root to rescan the filesystem.
# Use this if locate returns no results for a file you just created.
sudo updatedb
Run sudo updatedb if locate is silent. The database is only as fresh as the last cron job.
Managing the locate database
The database update process respects configuration in /etc/updatedb.conf. Fedora ships with sensible defaults that skip network mounts and temporary filesystems. Scanning NFS volumes or tmpfs slows down the update and wastes CPU cycles.
Here is how the configuration controls what gets scanned.
# /etc/updatedb.conf excerpt
# PRUNEFS lists filesystem types to skip during the scan.
# This prevents scanning network mounts or tmpfs which are usually irrelevant.
# Fedora defaults cover most common cases for desktop and server setups.
PRUNEFS="9p afs anon_inodefs auto autofs binfmt_misc cgroup cgroup2
configfs cpuset debugfs devpts devtmpfs ecryptfs exofs fuse
fusectl fusesshfs hugetlbfs iso9660 mqueue ncpfs nfs nfs4
nfsd overlay proc pstore rpc_pipefs securityfs selinuxfs
squashfs sysfs tmpfs tracefs ubifs udf usbfs"
Edit /etc/updatedb.conf to skip network mounts. Scanning NFS volumes slows down the database update and wastes CPU.
Common errors and how to read them
find prints errors to stderr. You will see Permission denied when find encounters a directory you cannot read. This is normal behavior. It does not mean find is broken. It means the current user lacks access.
find: '/root': Permission denied
find: '/var/lib/sss/mc': Permission denied
If you need to search those directories, run find with sudo. If you do not need them, restrict the search path to avoid the noise.
locate can return paths that no longer exist. This happens when a file is deleted but updatedb has not run since the deletion. Verify the path exists before using it.
# Check if a locate result actually exists on disk.
# -e tests for existence. Returns exit code 0 if true.
# Use this in scripts to filter out stale database entries.
locate -e config.yaml
The -e flag tells locate to verify existence before printing. This adds a small performance cost but filters out ghost paths. Use it when you need to trust the output immediately.
Trust the package manager for installed files. Use rpm -ql or dnf provides before running find on system directories.
Which tool to use
Use find when you need real-time accuracy and cannot tolerate stale results.
Use find when you must filter by permissions, size, modification time, or owner.
Use find when you need to perform actions like deletion or compression on the results.
Use locate when you need instant results and the file likely exists in the database.
Use locate when you are searching for a partial name across the entire system and speed matters more than freshness.
Use fd when you want a modern, colored, regex-capable alternative to find with better defaults.
Verify the path exists before you edit it. A stale locate result can lead you to a file that was moved or renamed.