$linuxjunkies
>

env(1)

Run a command in a modified environment or display environment variables.

UbuntuDebianFedoraArch

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

FlagWhat it does
-i, --ignore-environmentStart with an empty environment; only variables explicitly set are passed to the command
-u NAME, --unset=NAMERemove variable NAME from the environment before executing the command
-0, --nullOutput null bytes after each variable name instead of newlines (for use with xargs -0)
--block-signal=SIGBlock a signal from being delivered to the executed command (e.g., INT, TERM)
--unblock-signal=SIGUnblock a previously blocked signal
-S STRING, --split-string=STRINGSplit STRING on spaces/tabs and treat tokens as separate arguments
--list-signal-handlingDisplay how each signal is currently handled by the invoked program
--helpDisplay help message and exit
--versionDisplay version information and exit

Examples

Print all environment variables in NAME=VALUE format

env

Start a new bash shell with a completely empty environment (no PATH, HOME, etc.)

env -i bash

Execute bash with HOME and USER set to specific values, preserving other variables

env HOME=/tmp USER=nobody bash

Run Firefox with DISPLAY and DBUS variables removed (useful for sandboxing)

env -u DISPLAY -u DBUS_SESSION_BUS_ADDRESS firefox

Run Python script with only PATH and Python's default variables available

env -i PATH=/usr/bin:/bin python3 script.py

Prepend /opt/lib to LD_LIBRARY_PATH before running a custom program

env LD_LIBRARY_PATH=/opt/lib:$LD_LIBRARY_PATH ./myprogram

Execute date command with timezone set to UTC, leaving other variables intact

env TZ=UTC date

Print environment variables null-separated and safely sort them with xargs

env -0 | xargs -0 printf '%s\n' | sort

Related commands