Home > Computer Tutorials > Computer Knowledge > The ten most commonly used environment variables in Linux

The ten most commonly used environment variables in Linux

PHPz
Release: 2024-02-19 16:00:05
forward
1137 people have browsed it

The ten most commonly used environment variables in Linux

The Linux operating system provides a variety of environment variables for configuring and managing system behavior. This article will introduce the 10 most common environment variables in Linux, and give sample code and corresponding analysis.

1. PATH

The PATH environment variable determines the directory where the system looks for executable files. When you enter a command in the terminal, the system retrieves the executable file in the directory specified in the PATH variable.

Sample code:

echo $PATH
Copy after login

Output:

/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
Copy after login

Analysis:

In the above example, we used the echo $PATH command to display the value of the PATH environment variable. The output is a colon-separated list of paths that the system uses to find the executable file.

2. HOME

The HOME environment variable defines the user's home directory path and is often used by applications to determine the user's default working directory.

Sample code:

echo $HOME
Copy after login

Output:

/home/username
Copy after login

Analysis:

In the above example, we used the echo $HOME command to print the value of the HOME environment variable. The output is the current user's home directory path.

3. USER

USER environment variable contains the current user name.

Sample code:

echo $USER
Copy after login

Output:

username
Copy after login

Analysis:

In the above example, we used the echo $USER command to print the value of the USER environment variable. The output is the current username.

4. LANG

LANG environment variable determines the locale used by the system by default. It affects character encoding, date format, currency symbol and other related settings.

Sample code:

echo $LANG
Copy after login

Output:

en_US.UTF-8
Copy after login

Analysis:

In the above example, we used the echo $LANG command to print the value of the LANG environment variable. The output specifies that the system's default locale is American English and uses UTF-8 character encoding.

5. PWD

The PWD environment variable stores the path of the current working directory.

Sample code:

echo $PWD
Copy after login

Output:

/home/username/Documents
Copy after login

Analysis:

In the above example, we used the echo $PWD command to print the value of the PWD environment variable. The output is the path to the current working directory.

6. SHELL

SHELL environment variable specifies the default Shell interpreter for the current user.

Sample code:

echo $SHELL
Copy after login

Output:

/bin/bash
Copy after login

Analysis:

In the above example, we used the echo $SHELL command to print the value of the SHELL environment variable. The output is the current user's default shell interpreter path.

7. TERM

TERM environment variable defines the current terminal type and is used to control terminal display settings.

Sample code:

echo $TERM
Copy after login

Output:

xterm-256color
Copy after login

Analysis:

In the above example, we used the echo $TERM command to print the value of the TERM environment variable. The output results specify that the current terminal type is xterm-256color.

8. DISPLAY

DISPLAY environment variable specifies the display device of the current X server.

Sample code:

echo $DISPLAY
Copy after login

Output:

:0
Copy after login

Analysis:

In the above example, we used the echo $DISPLAY command to print the value of the DISPLAY environment variable. The output specifies that the current X server's display device is: 0.

9. EDITOR

EDITOR environment variable defines the text editor used by the current user by default.

Sample code:

echo $EDITOR
Copy after login

Output:

vim
Copy after login

Analysis:

In the above example, we used the echo $EDITOR command to print the value of the EDITOR environment variable. The output results specify that the default text editor used by the current user is vim.

10. LD_LIBRARY_PATH

LD_LIBRARY_PATH environment variable specifies the path where the dynamic linker searches for shared libraries at runtime.

Sample code:

echo $LD_LIBRARY_PATH
Copy after login

Output:

/usr/local/lib:/usr/lib:/lib
Copy after login

Analysis:

In the above example, we used the echo $LD_LIBRARY_PATH command to print the value of the LD_LIBRARY_PATH environment variable. The output is a colon-separated list of paths where the dynamic linker looks for shared libraries.

in conclusion

This article introduces the 10 most commonly used environment variables in Linux and provides sample code, output and analysis. These environment variables play an important role in configuring and controlling system behavior. By understanding and skillfully using these environment variables, you can better manage and customize your Linux system.

The above is the detailed content of The ten most commonly used environment variables in Linux. For more information, please follow other related articles on the PHP Chinese website!

source:mryunwei.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template