File system search
Related articles
This page provides a general overview of the utilities available to search your filesystem.
Contents
find
find might seem a little counter-intuitive at first. One would probably expect a find command to take as argument a file name and search the filesystem for files matching that name. For a program that does exactly that see #locate below.
Instead, find takes a set of directories and matches each file under them against a set of expressions. This design allows for some very powerful "one-liners" that would not be possible using the "intuitive" design described above (see some examples).
Installation
find is part of the findutils package, which is part of the base package group. That is, it is included by default in Arch.
Options
find has around 100 distinct options. However, they can be grouped into the following three categories.
Filesystem transversal
These include the following,
- whether or not to follow symbolic-links
- Optimizations to perform during transversal
- Whether or not produce a certain kind of diagnostic output
Expressions
Expressions are the meat and potatoes of find. They allow to filter the filesystem for a, potentially explicit, list files. In mathematical terminology, they allow you to define a relation on a list of files. This is the fundamental distinction between find and other search tools!
Expressions can be devided into the following categories
Tests
- file name
- depth of file under the directory
- file type
- modification date
- permissions of file
- shell command that takes the file as argument
Actions
- delete the file
- execute some shell command on the file
Operators
Operators allow you to combine sets of expressions together.
These include the basic logical operators such as AND, OR, NOT, as well as more complex combinors such as,
The power of find is the combination of this rich set of expressions.
Usage
Any usage of find takes the following general form:
$ find [filesystem transversal options] [list of directories to search] [list of expressions to perform]
For every file listed under the given directories, each expression is performed, from left to right. Thus, the order in which expressions are listed is important!
For example, the following commands give different results
find find
locate
locate
is a common Unix tool for quickly finding files by name. It offers speed improvements over the find tool by searching a pre-constructed database file, rather than the filesystem directly. The downside of this approach is that changes made since the construction of the database file cannot be detected by locate
. This problem is minimised by regular, typically scheduled use of the updatedb
command, which (as the name suggests) updates the database.
Installation
Although in other distros locate
and updatedb
are in the findutils package, they are no longer present in Arch's package. To use it, install the mlocate package. mlocate is a newer implementation of the tool, but is used in exactly the same way.
Before locate
can be used, the database will need to be created. To do this, simply run updatedb
as root.
Keeping the database up-to-date
When mlocate
is installed, a script is automatically scheduled to run daily via systemd
, to update the database. You can also manually run updatedb
as root at any time.
To save time, the updatedb
can be (and by default is) configured to ignore certain filesystems and paths by editing /etc/updatedb.conf
. man updatedb.conf
will tell you about the semantics of this file. It is worth noting that among the paths ignored in the default configuration (i.e. those in the "PRUNEPATHS" string) are /media
and /mnt
, so locate
may not discover files on external devices.
Desktop search engines
See also Wikipedia:List of search engines#Desktop search engines.
- Baloo — KDE's file indexing and search solution
- Catfish — Versatile file searching tool
- Docfetcher — A java open source desktop search application
- Gnome Search Tool — Default Gnome utility to search for files
- Gnome Search Tool No Nautilus — gnome-search-tool to search for files without GNOME Files or gnome-desktop
- Pinot — Personal search and metasearch tool
- Recoll — Full text search tool based on Xapian backend
- Searchmonkey — A powerful GUI search utility for matching regex patterns
- Strigi — Fast crawling desktop search engine with a Qt GUI.
- Tracker — All-in-one indexer, search tool and metadata database.