To show environment variables in Linux, you have several common commands:
- List all environment variables:
-
Use
printenv
orenv
to list all environment variables and their values:printenv
-
or
env
* Since the output can be long, you can pipe it to `less` for easier reading:
printenv | less
- Display a specific environment variable:
-
Use
printenv
followed by the variable name:printenv VARIABLE_NAME
-
Or use
echo
with a$
prefix:echo $VARIABLE_NAME
-
For example:
echo $HOME
printenv HOME
-
Search for variables containing a string:
-
Use
printenv
orset
withgrep
:printenv | grep STRING set | grep STRING
-
-
Note on commands:
printenv
is designed specifically for environment variables.env
can also list variables but is primarily used to run commands with modified environments.set
shows all shell variables, including environment, local, and shell functions, so its output is broader.
These methods allow you to view and manage environment variables effectively on Linux systems