A Practical Guide to elementary OS File Search with locate
Finding a file on a busy desktop can be harder than remembering where it was saved. Downloads may be spread across your home folder, an external drive, a shared work directory, or a cloud-synchronised folder. elementary OS includes a straightforward graphical file manager, but Linux also provides fast command-line tools for locating files by name.
The locate command is especially useful when you need a quick answer and already know part of a filename. It searches a prepared file index rather than checking every folder in real time. That makes it fast, although the results depend on when the index was last refreshed and which directories it is allowed to include.
What locate Actually Does
locate searches a database containing file and directory names. It does not normally open each file or inspect its contents. If you remember that a document was called something like tax-return-2024.pdf, the command can find matching paths almost immediately, even on a large home directory.
Open Terminal in elementary OS and try a simple search:
locate tax-return
The output may include paths such as:
/home/alex/Documents/tax-return-2024.pdf
/home/alex/Downloads/tax-return-notes.txt
The search is usually case-sensitive, so locate Report and locate report can produce different results. Use -i when you are unsure about capitalisation:
locate -i holiday
This is useful for the slightly chaotic naming habits that develop over a year: HolidayPhotos, holiday_photos, and HOLIDAY-2023 can all be found with one command.
The database records names and paths, not the current contents of files. A result does not guarantee that the item is still present. If a file was renamed or deleted after the last database update, locate may show an outdated path. Conversely, a newly downloaded file may not appear until the index is refreshed.
That distinction matters when searching an external SSD or a USB stick. A drive mounted only occasionally may not have been included in the database update, and a removable device can disappear while its old path remains in the results. Treat locate as a rapid name lookup, then check the actual path in Files or with another command.
Installing And Updating The Search Database
Many elementary OS installations include the locate command through a package such as plocate, while some do not. The exact package can vary with the elementary OS release and its Ubuntu base. You can check whether the command is available with:
command -v locate
If Terminal returns a path such as /usr/bin/locate, it is ready to use. If nothing appears, install the package from the command line:
sudo apt update
sudo apt install plocate
On some releases, the package may be named mlocate instead. It is better to search the available package list than to assume a package name:
apt search locate
The package manager will normally create or configure the required database service. To update the index manually, run:
sudo updatedb
The command may finish without displaying anything. That is normal. It scans the locations permitted by the system configuration and writes a fresh database for later searches. On a typical laptop with an SSD, the process should be reasonably quick, though the first run can take longer if there are many files.
A scheduled update may run automatically through a system timer or cron job. You can inspect relevant services with:
systemctl list-timers | grep -E 'locate|updatedb'
If you are using a laptop on an Australian NBN connection, remember that locate does not index files stored only online. A cloud service that displays placeholder files in Files may not have downloaded their names into a local directory. The index can search local metadata only; it cannot query Google Drive, OneDrive, or a web portal directly.
For community news, release notes, and practical desktop advice, the elementary OS community is also a useful place to keep an eye on changes that may affect packages and system tools.
Searching Precisely From Terminal
A plain search matches the text supplied in the command, often anywhere in the complete path. This means locate notes may return a large number of results from folders whose names contain “notes”. Narrow the output with -n when you only need the first few matches:
locate -n 20 notes
To count matching paths rather than print them all, use:
locate -c invoice
When you know the exact filename but not its location, place the name in quotes:
locate 'project brief.odt'
Quotes are important when a filename contains spaces or shell characters. For a case-insensitive exact basename search, -b checks the final component of the path:
locate -i -b '\project brief.odt'
The backslash tells locate to treat the value as a basename pattern rather than a broad path fragment. This avoids matches such as /home/alex/old-project brief.odt.backup.
Regular expressions provide more control. The -r option lets you search for patterns, although the exact regular-expression behaviour can vary slightly between implementations:
locate -r '/(jpg|jpeg|png)$'
That command looks for image files with common extensions. To find files with a year in their name:
locate -r '202[0-5].*\.pdf$'
If you want to see only paths that still exist, use -e:
locate -e -i presentation
This option can be slower because each candidate path must be checked against the live filesystem. It is a sensible choice when the database has not been updated recently or when you are cleaning up old search results.
You can combine results with ordinary shell tools. For example, to search for PDF files under your home directory and display only the first ten:
locate -i -e '.pdf' | grep "^$HOME/" | head -n 10
That example is helpful when a shared machine has several user accounts. It limits the visible results to your own home directory rather than showing system files and other users’ paths.
Privacy, Permissions And Index Scope
The locate database can reveal filenames and directory names to anyone who can read it. It may expose the names of legal documents, medical records, job applications, or folders belonging to a community organisation. The database does not show file contents, but filenames can still be sensitive.
The indexing tool generally runs with elevated privileges so it can scan permitted parts of the filesystem. It usually avoids directories such as /proc, /sys, /tmp, and some network or virtual filesystems. The configuration is commonly held in /etc/updatedb.conf, although the exact arrangement depends on the package installed.
Inspect the configuration before changing it:
grep -E 'PRUNE|SEARCHPATHS' /etc/updatedb.conf
Typical settings define filesystem types to exclude and paths that should not be indexed. If you keep private material in a dedicated directory, you can add that path to the exclusion list, then rebuild the database:
sudo updatedb
Make a backup of the configuration before editing it:
sudo cp /etc/updatedb.conf /etc/updatedb.conf.backup
Use a text editor with care, because a syntax error may prevent the index from being generated correctly. A path containing spaces may also need appropriate quoting or escaping according to the configuration format.
Shared computers deserve extra attention. A family laptop in Perth, a small business machine in Brisbane, or a community centre computer in regional New South Wales may have several accounts and removable drives. Avoid assuming that hiding a folder in the graphical Files app makes it invisible to system-wide tools. Access permissions still control whether a person can open a file, but the filename itself may appear in search results if the index permits it.
Network mounts and encrypted locations require separate consideration. A Samba share mounted under /media or a manually mounted encrypted volume may be absent from the index, particularly if it was unavailable during the scheduled update. After mounting a volume, you can explicitly refresh the database, but check that its contents are suitable for indexing first.
When To Use find, fd Or Content Search
locate is best when the question is, “Where is a file with this name?” It is less suitable when you need the newest file, a particular size, a precise directory, or a result that reflects the filesystem at this exact moment. For those tasks, find is more dependable.
To search your home directory for PDF files modified within the past seven days:
find "$HOME" -type f -iname '*.pdf' -mtime -7
To find files larger than 500 megabytes:
find "$HOME" -type f -size +500M
Because find walks through directories live, it can take longer than locate. It also reports current results rather than relying on a stale database. That makes it the better tool when you have just moved files, connected a drive, or deleted a large batch of old material.
Some users prefer fd, a modern alternative with simpler defaults and friendly output. It may not be installed by default, but once available it can search a directory quickly:
fd -i 'budget' "$HOME"
For searching inside files, use a content-search tool such as grep or ripgrep, rather than locate. For example:
grep -Ril --include='*.txt' 'renewal date' "$HOME/Documents"
This searches the text inside matching files, which is a completely different task from finding filenames. A PDF may require a text extraction tool before its contents can be searched, and image-based scans may need optical character recognition.
The graphical Files application remains useful for browsing, previewing, and opening the result. A practical workflow is to use locate for a fast filename lookup, confirm the path with locate -e or find, then open the item in Files. This combines the speed of the index with the accuracy and visual context of the desktop.
Keeping a small set of commands in a text note can help new users build confidence. Start with locate -i, locate -e, and find "$HOME" -type f; these cover many everyday searches without requiring complicated shell syntax.
A reliable routine is straightforward: install the package if necessary, run sudo updatedb, search by a distinctive part of the filename, and verify the result before acting on it. On an elementary OS computer, open Terminal now and run locate -i -e Documents to see which current paths in your home directory are available to the index.