WebMasterCampus
WEB DEVELOPER Resources

Linux env Command

Learn Linux env Command with examples


Linux env Command

In Linux, we can use “env” command is used to either print environment variables.

In Linux, env command also used by shell scripts to launch the correct interpreter.

env Command Syntax

>>  env [OPTION]... [-][NAME=VALUE]... [COMMAND [ARG]...]

env Command Example

env command without any argument print out a list of all environment variables.

>>  env
Options Description
-i
--ignore-environment
Start with an empty environment.
-0
--null
End each output line with a 0 (null) byte rather than a newline.
-u
--unset=NAME
Remove variable NAME from the environment.
--help Display a help message and exit.
--version Display version information and exit.
- Same as -i.

env -i Command Example

-i or –ignore-environment or only – : runs a command with an empty environment

>>  env -i your_command

Note: This completely clear out the environment, but it does not prevent your_command setting new variables.

>>  env -i /bin/sh

To clear the environment (creating a new environment without any existing environment variables) for a new shell.

env -u Command Example

env -u or –unset remove variable from the environment.

>> env -u variable_name
>> env -u XDG_VTNR

Removing XDG_VTNR environment variable which you can see in the image above in the output of just env.

env -0 Command

env -0 or –null command End each output line with NULL, not newline

>> env -0

env –version Command

env –version command Display version information and exit.

>> env --version

Commonly-Used Environment Variables

commonly-used environment variables Description
EDITOR The default file editor to be used.
HOME The current user's home directory.
SHELL The location of the current user's shell program.
TERM The current terminal emulation.
PATH Pathnames to be searched when executing commands.
MAIL Location of where mail is to be stored.
MANPATH Location of your manuals. See man command.
LOGNAME The name of the current user.
TZ The time zone used by the system clock.
Created with love and passion.