The env command
The env command lists every environment variable as NAME=value, one per line.
A practice shell in your browser that behaves like bash on Linux for these commands. Nothing you type leaves the page.
Usage
env env [-i] [-u NAME] [NAME=VALUE]... COMMAND [ARGUMENT]...
List environment variables, or run a command with changes. With no command, prints every exported variable as NAME=value. Given a command, runs it with the variables changed for that command only. A #! line often uses /usr/bin/env bash so the script finds bash wherever it is installed.
How to use env
List the environment
envEDITOR=nano HOME=/home/learner LANG=en_US.UTF-8 LOGNAME=learner OLDPWD=/home/learner/projects PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin PWD=/home/learner SHELL=/bin/bash USER=learner
Find one variable
env | grep HOMEHOME=/home/learner
printenv USERlearner
Options
| -i | start with no variables at all |
|---|---|
| -u NAME | leave out one variable |
More examples
env GREETING=hi printenv GREETINGhi
Questions about env
What is the difference between env and printenv?
With no arguments they print the same list. printenv NAME prints one value; env can also run a command with changed variables.
Related commands
Every everyday command on one page, to print or keep open: the Linux commands cheat sheet.