Home·Terminal commands

env

Processes and system

Usage

env [VAR=value] [command]

Prints the whole environment, or runs one command with extra variables attached; those variables apply to that single run only and nothing is left behind in your shell.

Common flags

FlagMeaning
envWith no arguments, print the whole environment.
VAR=value <command>Run the command with that variable added, for this run only.
-iStart from an empty environment, inheriting nothing.
-u <VAR>Unset one variable for the child process.

Examples

env | sort | grep -i proxy

Find the proxy variables that are breaking a download.

env NODE_ENV=production node app.js

Set a variable for one run without touching your shell.

env -i bash --noprofile --norc

A shell with nothing inherited, for reproducing a cron failure.

What is running and what is eating the machine. Identifying it comes before killing it.

How to read this

  • Square brackets [ ] mark a part you may leave out.
  • An ellipsis … means you can list more than one.
  • Flags are case-sensitive — in some commands -r and -R do different things.

Questions

Q. What does env do?

Prints the whole environment, or runs one command with extra variables attached; those variables apply to that single run only and nothing is left behind in your shell.

Q. How do I type it?

env [VAR=value] [command] — square brackets mark the parts you can leave out.

Q. How many flags are worth knowing?

4 are listed here; the full set is in man env. This command sits under Processes and system.

Related commands

man page: man env