- Unix Commands Reference
- Unix Commands - Home
cleanup Command in Linux
In the realm of Postfix, the cleanup daemon is an integral behind-the-scenes player responsible for processing incoming email messages. It doesn't function as a command you directly execute; rather, it operates as a service that quietly performs crucial tasks on received messages before they're delivered to recipients.
The cleanup daemon in Postfix is an essential, automated component that streamlines incoming email processing. While you don't directly control it with commands, you can influence its behavior through Postfix configuration options. By understanding these settings, you can tailor how cleanup standardizes, prepares, and routes incoming messages within your mail server environment.
Table of Contents
Here is a comprehensive guide to the options available with the cleanup command −
- Understanding cleanup Command in Linux
- Install cleanup Command in Linux
- How to use cleanup Command in Linux?
- Examples of cleanup Command in Linux
- Alternatives of cleanup Command in Linux
Understanding cleanup Command in Linux
The cleanup command in Postfix is responsible for processing inbound mail, inserting it into the incoming mail queue, and informing the queue manager of its arrival. It performs several important functions, including −
- Inserting missing message headers like From, To, Message-Id, and Date.
- Transforming envelope and header addresses to the standard form.
- Eliminating duplicate envelope recipient addresses.
- Optionally rewriting all envelope and header addresses according to the mappings specified in the canonical lookup tables.
- Optionally masquerading envelope sender addresses and message header addresses.
- Optionally expanding envelope recipients according to information found in the virtual lookup tables.
The cleanup daemon also performs sanity checks on the content of each message and logs problems and transactions to syslogd.
Install cleanup Command in Linux
To install and configure the cleanup daemon for Postfix in a Linux system, you'll need to ensure that Postfix is already installed. The cleanup daemon is responsible for canonicalizing and enqueuing messages in the Postfix queue.
It processes inbound mail, inserts it into the incoming mail queue, and informs the queue manager of its arrival. This daemon performs several essential functions, such as inserting missing message headers like From, To, Message-Id, and Date, transforming envelope and header addresses to a standard format, and eliminating duplicate envelope recipient addresses.
How to use cleanup Command in Linux?
The cleanup command in Postfix itself isn't one you directly execute with specific examples. It functions as a daemon that automatically processes incoming emails.
Options | Descriptions |
---|---|
local_header_rewrite_clients | This parameter determines if cleanup should rewrite message headers for clients submitting messages directly to the local Postfix server. Enabled by default, it ensures headers are in the expected format. |
always_add_missing_headers | This parameter controls whether cleanup inserts missing mandatory headers like From, To, Message-Id, and Date if they're absent in the incoming message. |
canonical(5) lookup tables | These tables define address rewriting rules. cleanup can optionally use these tables to transform envelope and header addresses to a standard format. |
masquerade_domains and masquerade_exceptions | These parameters configure address masquerading. cleanup can optionally strip domain information from sender and recipient addresses based on these settings. |
virtual(5) lookup tables | These tables allow cleanup to potentially expand envelope recipient addresses based on defined mappings. |
bounce_ourenormal_reject | This parameter controls how cleanup handles messages with invalid recipient addresses. It can bounce them or employ other rejection mechanisms. |
bounce_queue_spam | This parameter specifies the queue to use for bouncing spam messages identified by cleanup. |
debug_client and debug_see | These parameters enable debugging output for specific message processing stages, which can be helpful for troubleshooting cleanup issues. |
syslog_name and syslog_facility | These parameters define how cleanup logs messages to the system log. |
Examples of cleanup Command in Linux
Let’s explore a few examples of cleanup command in Linux −
Process and Queue an Email Message
To process and queue an email message, you can use the following command −
cleanup -f message_file
This canonicalizes and enqueues the message contained in message_file.
Remove Messages from the
To remove messages from the queue that are sent to a specific domain, you can use a combination of commands such as −
mailq | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if ($8 ~ /@example.com/ && $9 == "") print $1 }' | tr -d '*!' | postsuper -d -
This pipeline lists the queue, filters messages sent to example.com, and deletes them from the queue.
To reload the Postfix configuration after making changes to main.cf, you can use −
postfix reload
This command picks up changes to the configuration file without restarting the entire Postfix system.
Note − Remember, managing a mail server requires careful attention to detail and adherence to best practices to ensure secure and efficient operation. Always test your configurations in a safe environment before applying them to a production server.
Alternatives of cleanup Command in Linux
As Linux doesn't have a single "cleanup" command, but there are several tools and commands depending on what you want to clean up −
1. Package Manager Cleanup
Understanding and utilizing them effectively can greatly enhance the performance and reliability of your mail server.
Debian/Ubuntu −
sudo apt autoremove: Removes unused packages and dependencies. sudo apt clean: Clears package download cache.
CentOS/RHEL/Fedora −
sudo yum autoremove or sudo dnf autoremove (depending on version) sudo yum clean all or sudo dnf clean all
2. Temporary Files
Manually delete files in /tmp. Be cautious, some processes might use them.
3. Cache Directories
Identify and remove cache from specific applications (e.g., ~/.cache). Use tools like ncdu to visualize disk usage and find large directories.
4. Logs
Some applications have log rotation configured, but you might need to manually delete old logs.
Conclusion
The cleanup command is a utility in Linux that serves a very specific and useful purpose: it cleans up your file system by removing dangling symbolic links and empty directories.
cleanup is a powerful tool that can help maintain the integrity of your file system by ensuring that symbolic links are always valid and that empty directories don't clutter your file system. However, use it with caution, as it will permanently delete links and directories without confirmation.