How to Show PATH of Environment Variables in Linux?

The β€œPATH” environment variable is a variable that keeps a list of directories that the system explores for executable files. This allows users to run programs easily without defining the entire path to the .exe files. Additionally, users can set or update the β€œPATH” variable by assigning the new directory path. 

This article will demonstrate various methods to show PATH environment variables in Linux. 

Method 1: Using the β€œecho” Command

The β€œecho” is one of the most commands to show the β€œPATH” environment variables by executing with the symbol β€œ$” in the Linux terminal: 

$ echo $PATH

The output shows the complete path of environment variables in the terminal.

Method 2: Using the “cat” Command 

To show the PATH of the environment variable, you can execute the β€œcat” command with the β€œ/etc/environment” file. Additionally, the β€œgrep” command is utilized to fetch the value of the PATH variable and display it in the terminal:

$ cat /etc/environment | grep PATH

The command visualizes the path of an environment variable.

Optional: Update the PATH Environment Variable

To update the β€œPATH” variable, the β€œexport” command is utilized to assign the new directory to the β€œPATH” variable. In our case, specify the path β€œhome/itslinuxfoss” to the β€œPATH” as below:

$ export PATH=$PATH:/home/itslinuxfoss

In this way, a new path β€œ/home/itslinuxfoss” is set to the β€œPATH” environment variable.

Method 3: Using the β€œenv” Command

Users can utilize the β€œenv” command that fetches the value of β€œPATH” environment variables via the β€œgrep” command:

$ env | grep PATH

The output visualizes the complete path of an environment variable.

Method 4: Using the “set” Command

To view the PATH environment variable, you can execute the β€œset” command with the β€œgrep” by specifying the β€œPATH” variable in Linux:

$ set | grep PATH

The outcome of the above command returns the β€œPATH” value of the environment variable.

Method 5: Using the “printenv” Command

You can view the value of the PATH variable by executing the β€œprintenv” command:

$ printenv PATH

The above execution shows the path of environment variables in linux.

Conclusion

To show the PATH of an environment variable, execute the “echo“, “cat“, “env“, “set“, and “printenv” commands with the β€œPATH” variable. It comprises the number of directories the system requires to execute configuration files. Additionally, users can set or update the β€œPATH” variable by assigning the new directory path via the β€œexport” command. This article has explained all possible methods to show the PATH of an environment variable in Linux.