Today’s article is going to show you how to show all your environment variables in Linux. There are quite a few and some of them can be quite useful. If you don’t know what an environment variable is, we’ll cover that briefly as well.
So, what is an environment variable? It’s a static name for a dynamic value. In other words the system has information that varies, but using an environment variable will point to the dynamic information as though it was static.
As an example, we can use ‘echo $PWD‘ in the terminal and it will output the present working directory. If you change the directory and run that command again, it will output the new present working directory. You can do things like ‘echo $SHELL’ and it will tell you the shell you’re using, even if you’ve changed from the default shell. Things like that are the point of having environment variables.
These things really shine when used for things like scripting. They’re useful when you’re not certain of the architecture they’ll be used on and still want the script to work predictably wherever it is used. You’ll also see environment variables put to work in programming. They’re pretty handy, as I said!
If you’d like to see an example, read my article about clearing EXIF data for privacy’s sake. Scroll down to find the alias example I included and you’ll see the $PWD environment variable at work. See? It’s pretty easy and effective. So, let’s see a few ways to show all environment variables.
Show All Environment Variables:
Like most articles, you’re gonna need an open terminal. You can do that with your keyboard, by pressing
Now that you have your terminal open, we’ll start with the first way to show all the environment variables:
1 | env |
You can also use:
1 | printenv |
You can also use the following command, but I don’t recommend doing so. It’s here for the sake of completeness and the command will output a lot of gibberish that’s really of no value to the average user.
1 | set |
Now that you know how to show them, here are a few handy examples that further demonstrate what an environment variable does.
Show home with:
1 | echo $HOME |
Find the system language with:
1 | echo $LANGUAGE |
Or find the desktop environment in use with:
1 | echo $XDG_CURRENT_DESKTOP |
Those are just a few of the environment variables available to you as a Linux user. If you make use of these on a regular basis, please leave a comment explaining how you use them.
Closure:
Yup… Another article. Another step closer to the anniversary of this site. I still have some content to move over from the original site, but writing completely new stuff is pretty fun. Seriously, it’s pretty fun. Please feel encouraged to write an article or two, considering I normally take the whole month of January off!
Thanks for reading! If you want to help, or if the site has helped you, you can donate, register to help, write an article, or buy inexpensive hosting to start your own site. If you scroll down, you can sign up for the newsletter, vote for the article, and comment.