LinuxCommandLibrary

from

Display messages from specific senders

TLDR

List mail

$ from
copy

Display the number of messages stored
$ from --count
copy

List mail in the specified mailbox directory
$ MAIL=[path/to/mailbox] from
copy

Print the mail from the specified address
$ from --sender=[me@example.com]
copy

SYNOPSIS

from [-r] [file ...]

PARAMETERS

-r
    Use Return-Path header instead of From:

file
    Input file(s) containing mail message(s); uses stdin if omitted

DESCRIPTION

The from command is a lightweight utility designed to parse email messages and extract the sender's address or name from the header. Primarily used in mail processing pipelines, it reads the From: header line by default, outputting the sender information to standard output.

It processes one or more input files containing raw email messages in mbox format or reads from standard input if no files are provided. This makes it ideal for scripting tasks like logging senders in mail filters, cron jobs for mail monitoring, or integration with tools like procmail or maildrop.

The command performs simple header parsing, focusing solely on identifying the sender field. It handles standard RFC 822/2822 header formats but may not support complex MIME structures or folded headers perfectly. Output is plain text, typically the email address enclosed in quotes if present (e.g., "User ").

Common use cases include quick sender verification in shell scripts: from /var/mail/user or piping mail through it. It returns exit code 0 on success (sender found) and 1 otherwise, aiding in conditional scripting.

CAVEATS

Performs basic header parsing; may fail on malformed or non-standard headers. Assumes mbox-like format. No support for multi-part MIME or encrypted messages.

EXIT STATUS

0 if sender found, 1 if not or on error.

STANDARDS

Conforms to traditional Unix/POSIX mail tools; not strictly POSIX-specified.

HISTORY

Originated in early BSD Unix mail utilities around 1980s as part of the mail(1) suite. Maintained in GNU mailutils and bsd-mailx packages; minimal changes over decades due to simple functionality.

SEE ALSO

formail(1), mail(1), munpack(1), grep(1)

Copied to clipboard