env

system managementLinux/Unix
The env command is one of the most frequently used commands in Linux/Unix-like operating systems. env Display, set, or remove environment variables

Quick Reference

Command Name:

env

Category:

system management

Platform:

Linux/Unix

Basic Usage:

env [options] [arguments]

Common Use Cases

  • 1

    Environment inspection

    Display all environment variables to troubleshoot configuration issues

  • 2

    Isolated command execution

    Run commands with a clean or customized environment

  • 3

    Temporary variable modification

    Change environment variables for a single command without affecting the shell

  • 4

    Script portability

    Ensure consistent environment settings across different systems

Syntax

env [option]... [name=value]... [command [args]...]

Options

Option Description
-i, --ignore-environment Start with an empty environment
-0, --null End each output line with NUL, not newline
-u, --unset=NAME Remove variable NAME from the environment
-C, --chdir=DIR Change working directory to DIR before running command
-S, --split-string=S Process and split S into separate arguments
--debug Print debugging information
-v, --version Print version information
-h, --help Display help information

Examples

How to Use These Examples

The examples below show common ways to use the env command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.

# Basic Examples Basic
env
Display all environment variables.
env HOME=/tmp bash
Run bash with HOME set to /tmp.
# Advanced Examples Advanced
env -u HOME bash Run bash with the HOME variable unset. env -i bash Run bash with an empty environment. env PATH=/usr/bin:/bin my_program Run my_program with a specific PATH. env --chdir=/tmp my_program Change to the /tmp directory before running my_program.

Try It Yourself

Practice makes perfect! The best way to learn is by trying these examples on your own system with real files.

Understanding Syntax

Pay attention to the syntax coloring: commands, options, and file paths are highlighted differently.

Notes

The env command is used to manipulate the environment variables and execute commands with modified environments. When called without arguments, it displays all current environment variables. Environment variables are key-value pairs that can affect the behavior of programs on your system. They provide information like the current user (USER), the location of their home directory (HOME), and the search path for executable programs (PATH). The env command is particularly useful for: 1. Running programs with a modified environment without affecting the current shell 2. Clearing the environment before running a command (with -i option) 3. Debugging environment-related issues 4. Viewing all currently set environment variables It's commonly used in scripts and when launching programs that need specific environment configurations without permanently changing the system's environment.

Tips & Tricks

1

Use env without arguments to list all environment variables

2

Use env -i to start with a completely empty environment

3

Use env -u VARIABLE to unset a specific variable before running a command

4

Combine multiple variable assignments: env VAR1=value1 VAR2=value2 command

5

Use env --chdir=/path to change directory before running a command

Common Use Cases

Environment inspection

Display all environment variables to troubleshoot configuration issues

Isolated command execution

Run commands with a clean or customized environment

Temporary variable modification

Change environment variables for a single command without affecting the shell

Script portability

Ensure consistent environment settings across different systems

Debugging

Identify environment-related issues in applications and scripts

Related Commands

These commands are frequently used alongside env or serve similar purposes:

Use Cases

1

Environment inspection

Display all environment variables to troubleshoot configuration issues

2

Isolated command execution

Run commands with a clean or customized environment

3

Temporary variable modification

Change environment variables for a single command without affecting the shell

4

Script portability

Ensure consistent environment settings across different systems

5

Debugging

Identify environment-related issues in applications and scripts

Learn By Doing

The best way to learn Linux commands is by practicing. Try out these examples in your terminal to build muscle memory and understand how the env command works in different scenarios.

$ env
View All Commands