Skip to main content

env Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for listing, clearing, and overriding environment variables with env in Linux

The `env` command prints the current environment or runs another command with a modified environment. This cheatsheet covers listing variables, starting with a clean environment, overriding values temporarily, and common troubleshooting patterns.

Basic Syntax

Core env command forms.

CommandDescription
envPrint the current environment
env --helpShow available options
env --versionShow the installed env version
env -0Print variables separated with NUL bytes

Inspect Environment Variables

Use env with filters to inspect specific variables.

CommandDescription
`envsort`
`envgrep ‘^PATH='`
`envgrep ‘^HOME='`
`envgrep ‘^LANG='`

Run Commands with Temporary Variables

Set variables for one command without changing the current shell session.

CommandDescription
VAR=value env commandRun one command with a temporary variable
VAR1=dev VAR2=1 env commandSet multiple temporary variables
env PATH=/custom/bin:$PATH commandOverride PATH for one command
env LANG=C commandRun a command with the C locale
env HOME=/tmp bashStart a shell with a temporary home directory

Clean or Remove Variables

Start with a minimal environment or remove selected variables.

CommandDescription
env -i commandRun a command with an empty environment
env -i PATH=/usr/bin:/bin bash --noprofile --norcStart a mostly clean shell with a minimal PATH
env -u VAR commandRun a command without one variable
env -u http_proxy commandRemove a proxy variable for one command
env -i VAR=value commandRun a command with only the variables you set explicitly

Common Variables

These variables are often inspected or overridden with env.

VariableDescription
PATHDirectories searched for commands
HOMECurrent user’s home directory
USERCurrent user name
SHELLDefault login shell
LANGLocale and language setting
TZSystem timezone (e.g. America/New_York)
EDITORDefault text editor
TERMTerminal type (e.g. xterm-256color)
TMPDIRDirectory for temporary files
PWDCurrent working directory

Troubleshooting

Quick checks for common env issues.

IssueCheck
A temporary variable does not persistenv VAR=value command affects only that command and its children
A command is not found after env -iAdd a minimal PATH, such as /usr/bin:/bin
Output is hard to parse safelyUse env -0 with tools that support NUL-delimited input
A variable is still visible in the shellenv does not modify the parent shell; use export or unset the variable in the shell itself
A locale-sensitive command behaves differentlyCheck whether LANG or related locale variables were overridden

Use these guides for broader environment-variable workflows.

GuideDescription
How to Set and List Environment Variables in LinuxFull guide to listing and setting environment variables
export Command in LinuxExport shell variables to child processes
Bashrc vs Bash ProfileUnderstand shell startup files
Bash cheatsheetQuick reference for Bash syntax and variables