Clean
Remove comments from .env files while preserving variable values and structure.
Cleaning Comments (clean)
The clean command strips comment lines (#) and inline comments from your .env files while preserving all variable keys, values, and structural spacing.
bash
By default, running envnix clean reads your .env file and outputs the cleaned result to .env.clean.
Force Mode (--force / -f)
When passed with the --force (or -f) flag, envnix clean will overwrite the original .env file directly in-place:
bash
Options
The clean command supports options similar to generate:
| Option | Shorthand | Description |
|---|---|---|
--input <file> | -i | Custom input file instead of the default .env |
--output <file> | -o | Custom output file path |
--force | -f | Clean directly in-place (overwrites input file instead of .clean) |
--all | -a | Clean all matched .env* files in the directory |
--dry-run | Print the cleaned output to stdout without modifying disk | |
--verbose | Print verbose logs for debugging | |
--quiet | -q | Only output errors |
Example Usage
Given an input .env file:
env
Running envnix clean will produce:
env
Clean All Environment Files
To clean all matched .env* files in your project directory at once:
bash
How is this guide?
Last updated on August 5, 2026