NOTMUCH-SEARCH-TERMS(7)
β¨ notmuch-search-terms(7) β¨
okay bestie, this is the manual page for notmuch search terms π it's the syntax for notmuch queries, and if you've ever been like "why is my search not searching", this is the page. no cap.
πΈ NAME πΈ
notmuch-search-terms β syntax for notmuch queries. that's the vibe. periodt π
π SYNOPSIS π
notmuch count [option ...] <search-term> ...
notmuch dump [--gzip] [--format=(batch-tag|sup)] [--output=<file>] [--]
[<search-term> ...]
notmuch reindex [option ...] <search-term> ...
notmuch search [option ...] <search-term> ...
notmuch show [option ...] <search-term> ...
notmuch tag +<tag> ... -<tag> [--] <search-term> ...
π DESCRIPTION π
okay so several notmuch commands accept a common syntax for search terms. several. not all, but the cool ones. π«Ά
The search terms can consist of free-form text (and quoted phrases) which will match all messages that contain all of the given terms/phrases in the body, the subject, or any of the sender or recipient headers. so like, it's giving "search everywhere in the message" energy. β¨
As a special case, a search string consisting of exactly a single asterisk ("*") will match all messages. literally all of them. the whole mailbox. no filter. iconic π
π Search prefixes π
In addition to free text, the following prefixes can be used to force terms to match against specific portions of an email, (where <brackets> indicate user-supplied values). so you can be like "bestie, look only in the body" or "only in the subject". π
Some of the prefixes with <regex> forms can be also used to restrict the results to those whose value matches a regular expression (see regex(7) <https://manpages.debian.org/regex.7.html>) delimited with //, for example:
notmuch search 'from:"/bob@.*[.]example[.]com/"'
okay so that's a regex inside a from: prefix, delimited by slashes. slay. π
Now the prefixes themselves. one bullet each, no skipping. π
body:<word-or-quoted-phrase>β Match terms in the body of messages. the body. the main character of the email. πfrom:<name-or-address>orfrom:/<regex>/β Thefrom:prefix is used to match the name or address of the sender of an email message. who sent it? that's the question. πto:<name-or-address>β Theto:prefix is used to match the names or addresses of any recipient of an email message, (whether To, Cc, or Bcc). so not just the To line, bestie. Cc and Bcc count too. π«Άsubject:<word-or-quoted-phrase>orsubject:/<regex>/β Any term prefixed withsubject:will match only text from the subject of an email. Searching for a phrase in the subject is supported by including quotation marks around the phrase, immediately followingsubject:. so likesubject:"cute cat pics"or whatever. no cap. β¨attachment:<word>β Theattachment:prefix can be used to search for specific filenames (or extensions) of attachments to email messages. yes, you can find that one PDF. we've all been there. πmimetype:<word>β Themimetype:prefix will be used to match text from the content-types of MIME parts within email messages (as specified by the sender). somimetype:text/plainetc. it's giving MIME energy. π§tag:<tag>ortag:/<regex>/oris:<tag>oris:/<regex>/β Fortag:andis:valid tag values includeinboxandunreadby default for new messages added bynotmuch-new<#notmuch-new-1> as well as any other tag values added manually withnotmuch-tag<#notmuch-tag-1>. so tags are your little labels and you can search by them. πid:<message-id>ormid:<message-id>ormid:/<regex>/β Forid:andmid:, message ID values are the literal contents of theMessage-ID:header of email messages, but without the<,>delimiters. so no angle brackets, bestie. πthread:<thread-id>β Thethread:prefix can be used with the thread ID values that are generated internally by notmuch (and do not appear in email messages). These thread ID values can be seen in the first column of output fromnotmuch-search<#notmuch-search-1>. so not a thing you'll find in the email itself. internal only. π₯thread:{<notmuch query>}β Threads may be searched for indirectly by providing an arbitrary notmuch query in{}. For example, the following returns threads containing a message from mallory and one (not necessarily the same message) with Subject containing the word"crypto".
% notmuch search 'thread:"{from:mallory}" and thread:"{subject:crypto}"'
The performance of such queries can vary wildly. To understand this, the user should think of the query thread:{<something>} as expanding to all of the thread IDs which match <something>; notmuch then performs a second search using the expanded query. so it's a query inside a query. inception vibes. π€―
path:<directory-path>orpath:<directory-path>/**orpath:/<regex>/β Thepath:prefix searches for email messages that are in particular directories within the mail store. The directory must be specified relative to the top-level maildir (and without the leading slash). By default,path:matches messages in the specified directory only. The"/**"suffix can be used to match messages in the specified directory and all its subdirectories recursively.path:""matches messages in the root of the mail store and, likewise,path:**matches all messages.
path: will find a message if any copy of that message is in the specific directory.
folder:<maildir-folder>orfolder:/<regex>/β Thefolder:prefix searches for email messages by maildir or MH folder. For MH-style folders, this is equivalent topath:. For maildir, this includes messages in the"new"and"cur"subdirectories. The exact syntax for maildir folders depends on your mail configuration. For maildir++,folder:""matches the inbox folder (which is the root in maildir++), other folder names always start with".", and nested folders are separated by"."s, such asfolder:.classes.topology. For"file system"maildir, the inbox is typicallyfolder:INBOXand nested folders are separated by slashes, such asfolder:classes/topology.
folder: will find a message if any copy of that message is in the specific folder.
date:<since>..<until>ordate:<date>β Thedate:prefix can be used to restrict the results to only messages within a particular time range (based on theDate:header).
See DATE AND TIME SEARCH below for details on the range expression, and supported syntax for <since> and <until> date and time expressions.
The time range can also be specified using timestamps without including the date prefix using a syntax of:
<initial-timestamp>..<final-timestamp>
Each timestamp is a number representing the number of seconds since 1970-01-01 00:00:00 UTC. Specifying a time range this way is considered legacy and predates the date prefix. so old school. legacy π΅
lastmod:<initial-revision>..<final-revision>β Thelastmod:prefix can be used to restrict the result by the database revision number of when messages were last modified (tags were added/removed or filenames changed). Negative revisions are interpreted relative to the most recent database revision (seecount --lastmod<#cmdoption-count-lastmod>). This is usually used in conjunction with the--uuidargument tonotmuch-search<#notmuch-search-1> to find messages that have changed since an earlier query. so it's like "what changed since last time?" π΅οΈββοΈquery:<name>β Thequery:prefix allows queries to refer to previously saved queries added withnotmuch-config<#notmuch-config-1>. saved queries are bestie behavior. πproperty:<key>=<value>β Theproperty:prefix searches for messages with a particular<key>=<value>property pair. Properties are used internally by notmuch (and extensions) to add metadata to messages. A given key can be present on a given message with several different values. Seenotmuch-properties<#notmuch-properties-7> for more details. metadata moment. β¨sexp:<subquery>β Thesexp:prefix allows subqueries in the format documented innotmuch-sexp-queries<#notmuch-sexp-queries-7>. Note that subqueries containing spaces must be quoted, and any embedded double quotes must be escaped (see Quoting). so parentheses and quotes, be careful. π«
User defined prefixes are also supported, see notmuch-config <#notmuch-config-1> for details. make your own prefixes, main character energy. π
β‘ Operators β‘
In addition to individual terms, multiple terms can be combined with Boolean operators (and, or, not, and xor). Each term in the query will be implicitly connected by a logical AND if no explicit operator is provided (except that terms with a common prefix will be implicitly combined with OR). The shorthand '-<term>' can be used for 'not <term>' but unfortunately this does not work at the start of an expression. Parentheses can also be used to control the combination of the Boolean operators, but will have to be protected from interpretation by the shell, (such as by putting quotation marks around any parenthesized expression). so yes, the shell is the hater here. protect your parentheses. π€
In addition to the standard boolean operators, Xapian provides several operators specific to text searching.
notmuch search term1 NEAR term2
will return results where term1 is within 10 words of term2. The threshold can be set like this:
notmuch search term1 NEAR/2 term2
The search
notmuch search term1 ADJ term2
will return results where term1 is within 10 words of term2, but in the same order as in the query. The threshold can be set the same as with NEAR:
notmuch search term1 ADJ/7 term2
so NEAR is "close enough", ADJ is "close enough and in order". slay. π₯
π± Stemming π±
Stemming in notmuch means that these searches
notmuch search detailed
notmuch search details
notmuch search detail
will all return identical results, because Xapian first "reduces" the term to the common stem (here 'detail') and then performs the search.
There are two ways to turn this off: a search for a capitalized word will be performed unstemmed, so that one can search for "John" and not get results for "Johnson"; phrase searches are also unstemmed (see below for details). Stemming is currently only supported for English. Searches for words in other languages will be performed unstemmed. so English only, bestie. other languages get the raw unstemmed treatment. π
π¦ Wildcards π¦
It is possible to use a trailing '*' as a wildcard. A search for 'wildc*' will match 'wildcard', 'wildcat', etc. so the star goes at the end, not the beginning. don't be chaotic. β¨
π Boolean and Probabilistic Prefixes π
Xapian (and hence notmuch) prefixes are either boolean, supporting exact matches like "<tag:inbox>" or probabilistic, supporting a more flexible term based searching. Certain special prefixes are processed by notmuch in a way not strictly fitting either of Xapian's built in styles. The prefixes currently supported by notmuch are as follows.
- Boolean β
tag:,id:,thread:,folder:,path:,property: - Probabilistic β
body:,to:,attachment:,mimetype: - Special β
from:,query:,subject:,sexp:
π¬ Terms and phrases π¬
In general Xapian distinguishes between lists of terms and phrases. Phrases are indicated by double quotes (but beware you probably need to protect those from your shell) and insist that those unstemmed words occur in that order. One useful, but initially surprising feature is that the following are equivalent ways to write the same phrase.
"a list of words"a-list-of-wordsa/list/of/wordsa.list.of.words
Both parenthesised lists of terms and quoted phrases are ok with probabilistic prefixes such as to:, from:, and subject:. For prefixes supporting regex search, the parenthesised list should be quoted. In particular
...it's giving parentheses do the most, bestie. Like:
subject:"(pizza free)"
is literally the same thing as
subject:pizza and subject:free
Both of those match a subject like "Free Delicious Pizza", but
subject:"pizza free"
will not match it. So if you want the words to be found together-ish, parens are your girl. π
β¨ Quoting β¨
Double quotes are also what the notmuch query parser uses to protect boolean terms, regular expressions, or subqueries that have spaces or other special characters in them, like:
tag:"a tag"
folder:"/^.*/(Junk|Spam)$/"
thread:"{from:mallory and date:2009}"
Same energy as with phrases β you gotta shield those double quotes from your shell, so:
% notmuch search 'folder:"/^.*/(Junk|Spam)$/"'
% notmuch search 'thread:"{from:mallory and date:2009}" and thread:{to:mallory}'
And if you need actual double quotes inside a query string, you double them up to escape them. Yes, it looks unhinged. Yes, it works. π
% notmuch search 'tag:"""quoted tag"""'
% notmuch search 'sexp:"(or ""wizard"" ""php"")"'
πΈ DATE AND TIME SEARCH πΈ
notmuch gets a whole bunch of standard and natural ways to say dates and times, both absolute ("2012-10-24") and relative ("yesterday"). You can stack up as many relative terms as you want ("1 hour 25 minutes") and you can even take an absolute date/time and adjust it with relative terms. The list below is non-exhaustive β it's just a lil tour of the syntax. π°οΈ
The range expression
date:<since>..<until>
This one restricts your results to only messages from <since> to <until>, based on the Date: header. π
<since> and <until> can be vague times like "yesterday". When they're fuzzy like that, <since> is taken as the earliest time it could possibly describe (so, the beginning of yesterday) and <until> is taken as the latest time it could describe (the end of yesterday). Same logic: date:january..february matches from the beginning of January to the end of February. Iconic behaviour, honestly.
If you're specifying a time range with timestamps alongside the date prefix, each timestamp must be preceded by @ (ASCII hex 40). And as above, each timestamp is a number for the seconds since 1970-01-01 00:00:00 UTC. Like:
date:@<initial-timestamp>..@<final-timestamp>
Okay so currently, spaces in range expressions are not supported. You can swap the spaces for_, or (in most cases)-, or (in some cases) just leave the spaces out entirely. The examples in this man page use spaces for clarity, but that's a readability thing, not a copy-paste thing. π
Open-ended ranges are supported too! So you can do date:..<until> or date:<since>.. to not limit the start or the end time respectively. Go off. π₯
Single expression
date:<expr> is a shorthand for date:<expr>..<expr>. So for example, date:monday matches from the beginning of Monday until the end of Monday. One word, whole day. π
Relative date and time
[N|number] (years|months|weeks|days|hours|hrs|minutes|mins|seconds|secs) [...]
- All of these refer to the past, they can be repeated, and they'll be accumulated. π
- Units can be abbreviated to any length, with the otherwise ambiguous single
mbeingmfor minutes andMfor months. (Case matters, bestie. Don't get caught out. π) - Number can also be written out:
one,two, ...,ten,dozen,hundred. And the unit can be preceded by "last" or "this" (e.g., "last week" or "this month"). ποΈ - When you combine it with an absolute date and time, the relative date and time spec will be relative from that specified absolute date and time.
- Examples:
5M2d,two weeks
Supported absolute time formats
H[H]:MM[:SS] [(am|a.m.|pm|p.m.)]H[H] (am|a.m.|pm|p.m.)HHMMSSnownoonmidnight- Examples:
17:05,5pm
Supported absolute date formats
YYYY-MM[-DD]DD-MM[-[YY]YY]MM-YYYYM[M]/D[D][/[YY]YY]M[M]/YYYYD[D].M[M][.[YY]YY]D[D][(st|nd|rd|th)] Mon[thname] [YYYY]Mon[thname] D[D][(st|nd|rd|th)] [YYYY]Wee[kday]
Month names can be abbreviated at three or more characters. Weekday names can be abbreviated at three or more characters. Short queen behaviour. β¨
Examples: 2012-07-31, 31-07-2012, 7/31/2012, August 3
Time zones
(+|-)HH:MM(+|-)HH[MM]
Some time zone codes too, e.g. UTC, EET. π
π SEE ALSO π
notmuch <#notmuch-1>, notmuch-config <#notmuch-config-1>, notmuch-count <#notmuch-count-1>, notmuch-dump <#notmuch-dump-1>, notmuch-hooks <#notmuch-hooks-5>, notmuch-insert <#notmuch-insert-1>, notmuch-new <#notmuch-new-1>, notmuch-properties <#notmuch-properties-7>, notmuch-reindex <#notmuch-reindex-1>, notmuch-reply <#notmuch-reply-1>, notmuch-restore <#notmuch-restore-1>, notmuch-search <#notmuch-search-1>, notmuch-show <#notmuch-show-1>, notmuch-tag <#notmuch-tag-1>
Author
Carl Worth and many others π«Ά
Copyright
2009-2026, Carl Worth and many others
and that's the whole page bestie, you ate it up π this was version 0.40, dated Jan 31, 2026, and the page is NOTMUCH-SEARCH-TERMS(7) β go forth and query, you absolute icon ππ¦
π¦ where this page comes from
- fedora 44: notmuch 0.40-1.fc44 Β· GPL-3.0-or-later
- fedora 44: notmuch 0.40-1.fc44 Β· GPL-3.0-or-later
- nixos 26.05: notmuch 0.40
- ubuntu resolute: notmuch 0.40-1ubuntu1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms