When you log into a Linux terminal, the system automatically sets up dozens of hidden background variables. These variables dictate how your terminal behaves, where it looks for executable programs, what language it displays, and what your default text editor is.
These hidden settings are called Environment Variables. If you are writing bash scripts, installing complex software (like Java or Node.js), or troubleshooting why a command won’t run, you need to know how to view these variables.
The fastest way to see them all is using the env command.
How to Use the env Command
To print a list of every active environment variable for your current session, open your terminal and simply type:
env
Press Enter. Your screen will instantly fill with a long list of text formatted as VARIABLE_NAME=value.
Important Environment Variables
As you scroll through the output of the env command, you will notice several critical system variables:
- USER= Shows the name of the Linux account you are currently logged in as.
- HOME= Shows the absolute path to your current user’s home directory (e.g.,
/home/ubuntu). - PWD= Shows your “Print Working Directory”, which is the exact folder you are currently navigating in the terminal.
- SHELL= Shows which command-line interpreter you are using (usually
/bin/bashor/bin/zsh). - PATH= This is the most important variable. It contains a colon-separated list of directories (like
/usr/binand/usr/local/bin). When you type a command likelsorpython, Linux searches through these exact directories to find the executable file. If a program is not inside one of these PATH folders, the terminal will throw a “command not found” error.
Searching for a Specific Variable
Because the env command prints dozens of lines of output, it can be hard to read. If you only want to check the value of one specific variable (for example, you want to see your PATH), you can pipe the output into the grep search command.
Type the following:
env | grep PATH
This filters out all the noise and only prints the line containing the word “PATH”. Alternatively, you can directly print the value of a specific variable using the echo command by adding a dollar sign (e.g., echo $PATH).