env(1)
Run a command in a modified environment or display environment variables.
Synopsis
env [OPTION]... [NAME=VALUE]... [COMMAND [ARG]...]Description
The env command executes a program in a modified environment. If no command is specified, it prints the current environment variables. It's commonly used to clear the environment, set specific variables, or isolate a command from the caller's environment.
When invoked without arguments, env behaves like printenv, listing all exported variables in NAME=VALUE format. When a command is provided, variables are set and the command is executed as a child process.
Common options
| Flag | What it does |
|---|---|
-i, --ignore-environment | Start with an empty environment; only variables explicitly set are passed to the command |
-u NAME, --unset=NAME | Remove variable NAME from the environment before executing the command |
-0, --null | Output null bytes after each variable name instead of newlines (for use with xargs -0) |
--block-signal=SIG | Block a signal from being delivered to the executed command (e.g., INT, TERM) |
--unblock-signal=SIG | Unblock a previously blocked signal |
-S STRING, --split-string=STRING | Split STRING on spaces/tabs and treat tokens as separate arguments |
--list-signal-handling | Display how each signal is currently handled by the invoked program |
--help | Display help message and exit |
--version | Display version information and exit |
Examples
Print all environment variables in NAME=VALUE format
envStart a new bash shell with a completely empty environment (no PATH, HOME, etc.)
env -i bashExecute bash with HOME and USER set to specific values, preserving other variables
env HOME=/tmp USER=nobody bashRun Firefox with DISPLAY and DBUS variables removed (useful for sandboxing)
env -u DISPLAY -u DBUS_SESSION_BUS_ADDRESS firefoxRun Python script with only PATH and Python's default variables available
env -i PATH=/usr/bin:/bin python3 script.pyPrepend /opt/lib to LD_LIBRARY_PATH before running a custom program
env LD_LIBRARY_PATH=/opt/lib:$LD_LIBRARY_PATH ./myprogramExecute date command with timezone set to UTC, leaving other variables intact
env TZ=UTC datePrint environment variables null-separated and safely sort them with xargs
env -0 | xargs -0 printf '%s\n' | sort