How To View Environment Variables In Linux

Environment variables are a set of dynamic named values stored within the system that are used by applications launched in shells or subshells. In Linux systems, environment variables provide a simple way to share configuration settings between multiple applications and processes.

Listing all Environment Variables

To get a list of all environment variables in Linux, you can use the printenv command without any arguments. Here’s how to do it:

        printenv
        

This will output a list of all environment variables along with their values. The output will be in the format VARIABLE=value.

Listing a Specific Environment Variable

If you are interested in the value of a specific variable, you can pass the name of the variable as an argument to the printenv command. For example, to print the value of the HOME variable, you would run:

        printenv HOME
        

This will output only the value of the HOME variable.

Using the echo Command

Another way to print the value of a specific environment variable is to use the echo command. The name of the variable is preceded by a $ symbol. Here’s an example:

        echo $HOME
        

This will also print the value of the HOME variable.

Conclusion

Understanding how to view environment variables in Linux is paramount in managing your Linux environment effectively. With the use of the printenv and echo commands, you have the ability to view all or specific environment variables making debugging and general management tasks easier.