Using The Linux env Command To See “Environment” Variables
When you’re at the Linux command line, you’re working in the “bash shell environment”, often just referred to as the “shell”.
This environment uses several variables to manage itself and provide you with information.
To see your current environment variables, simply type in: env which stands for environment and press Enter.
These variables are shown in upper case letters and you use them in upper case with Linux commands.
Linux Commands Training Tips:
The Linux System Administration concepts and commands covered here apply to ALL other Linux distributions, including: Debian, Ubuntu, Slackware, SUSE, openSUSE, Red Hat, Fedora, Edubuntu – and Kubuntu.
Viewing Your Environment Variables While Working As A Regular User
As a regular user, run the command below to see your current environment variables.
- $ env | less
When you are working as a regular (non-root) user, you have a group of settings in your environment variables and when you are working as the root (main Linux system administration user) you have a similar, but somewhat different set of these variables.
Viewing Your Environment Variables While Working As The root User
Now open a different terminal emulation window and do the steps below.
To start working as the root user, run the following command (without the quotes): “su -” (if you’re not using a variation of Ubuntu Linux) – or run “sudo -i” (if you are using a variation).
Now run the same env command as above and compare the difference in the output between the regular and root users.
For example, in the first terminal window the PWD variable for a regular user will show /home/username, where username is the currently logged in user (in that window). And this variable will show /root in the window for the root user. If necessary, press q to quit out of less.