
postalias Command in Linux
The postalias command in Linux is used to maintain the Postfix alias databases. Postfix alias databases are lookup tables that define email forwarding rules and address expansions. These databases are used by Postfix to rewrite recipient addresses and route emails accordingly.
The postalias command processes alias files and updates the corresponding database files used by Postfix for email routing.
Table of Contents
Here is a comprehensive guide to the options available with the postalias command â
Syntax of postalias Command
The syntax of the postalias command in Linux is as follows:
postalias [options] [aliastype:][fileâ¦]
In the above syntax, the [options] field is used to specify options to change the command’s output. The [aliastype:][file…] field is used to specify the alias file and its database type, for example, hash:/etc/aliases.
Options of postalias Command
The options of the Linux postalias command are listed below:
Option | Description |
---|---|
-c config_dir | Reads main.cf from the specified directory instead of the default. |
-d key | Searches for key in the maps and removes one entry per map. Reads from standard input if - is specified. |
-f | Prevents folding the lookup key to lowercase when creating or querying a table. |
-i | Enables incremental mode, reading entries from standard input without truncating an existing database. |
-N | Includes a terminating null character in lookup keys and values, depending on OS defaults. |
-n | Excludes a terminating null character in lookup keys and values, depending on OS defaults. |
-o | Prevents dropping root privileges when processing a non-root input file. |
-p | Ignores input file permissions and creates new files with default permissions (0644). |
-q key | Searches maps for key and outputs the first value found. Reads from standard input if - is specified. |
-r | Updates a table without warnings when modifying existing entries. |
-s | Retrieves all database elements and outputs them in key-value format. |
-v | Enables verbose logging; multiple -v options increase verbosity. |
-w | Updates a table without warnings and ignores attempts to modify existing entries. |
Examples of postalias Command in Linux
This section explores how to use the postalias command in Linux with examples:
Creating or Updating an Alias Database
To create a database or update an alias database, use the postalias command in the following way:
sudo postalias /etc/aliases
Listing All Entries
To list all entries, use the -s option:
sudo postalias -s /etc/aliases

Querying an Alias
To query an alias, use the -q option with the key. For example, to find the value of the user1 key, use the following command:
sudo postalias -q user1 /etc/aliases

Deleting an Alias Entry
To delete an alias entry, use the -d option with the key. For example, to remove the entry of user1 key, use the postalias command in the following way:
sudo postalias -d user1 /etc/aliases
To verify, list the entries:

Updating the Database without Warnings
To update the alias database without warnings, use the -r option:
sudo postalias -r /etc/aliases
The above command updates the alias database without warnings when modifying existing entries. If an alias already exists, it will be replaced without prompting.
Updating the Database without Warnings and Ignoring Modifications
To update an alias database without warnings and ignore modification attempts for existing entries, use the -w option:
sudo postalias -w /etc/aliases
The above command updates the alias database without warnings but ignores attempts to modify existing entries. If an alias already exists, it remains unchanged.
Creating a Database with a Specific Alias Type
To create a database with a specific alias type, specify the alias type explicitly. For example, to create a .db file with the hash alias type use the postalias command in the following way:
sudo postalias hash:/etc/aliases
The above command creates a .db file in the /etc directory.

Common database types are mentioned below:
Type | Output File |
---|---|
btree | file_name.db (requires db support). |
cdb | file_name.cdb (requires cdb support). |
dbm | file_name.pag and file_name.dir (requires dbm support). |
hash | file_name.db (requires db support). |
sdbm | file_name.pag and file_name.dir (requires sdbm support). |
Enable Verbose Logging
To enable verbose logging, use the -v option:
sudo postalias -v /etc/aliases

Similarly, to increase the verbosity level, use the -v multiple times.
sudo postalias -vv /etc/aliases
Each additional -v increases the logging detail
Conclusion
The postalias command in Linux is used to manage Postfix alias databases, which define email forwarding rules and address expansions. It processes alias files and updates database files for email routing. The command supports various options for modifying alias entries, querying specific addresses, listing all entries, and updating databases.
This tutorial covered the postalias command, its syntax, options, and usage in Linux with examples.