env is used to either print environment variables. It is also used to run a utility or command in a custom environment. In practice, env has another common use. It is often used by shell scripts to launch the correct interpreter. In this usage, the environment is typically not changed.
env [OPTION]... [-][NAME=VALUE]... [COMMAND [ARG]...]
Options of env command
1. Without any argument : print out a list of all environment variables.
2. -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.
EXAMPLE : To clear the environment (creating a new environment without any existing environment variables) for a new shell
In this, it clears all the environment variable and then new shell sets the environment variable PWD. Thus in this new shell when we execute env, we only see one environment variable PWD.
3. -u or –unset: remove variable from the environment
$ env -u variable_name
EXAMPLE : Removing XDG_VTNR environment variable which you can see in the image above in the output of just env.
4. -0 or –null: End each output line with NULL, not newline
$ env -0
5. –version: Display version information and exit.
$ env --version
6. –help: Display a help message and exit.
$ env --help
- bg command in Linux with Examples
- apt command in linux with examples
- tee command in Linux with examples
- Cat command in Linux with examples
- until command in Linux with Examples
- rcp Command in Linux with examples
- help Command in Linux with examples
- if command in linux with examples
- ps command in Linux with Examples
- seq command in Linux with Examples
- man command in Linux with Examples
- ex command in Linux with examples
- df Command in Linux with examples
- ar command in Linux with examples
- ssh command in Linux with Examples
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.