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.
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
Output:
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
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.
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
Output:
/home/username
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.
USER environment variable contains the current user name.
Sample code:
echo $USER
Output:
username
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.
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
Output:
en_US.UTF-8
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.
The PWD environment variable stores the path of the current working directory.
Sample code:
echo $PWD
Output:
/home/username/Documents
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.
SHELL environment variable specifies the default Shell interpreter for the current user.
Sample code:
echo $SHELL
Output:
/bin/bash
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.
TERM environment variable defines the current terminal type and is used to control terminal display settings.
Sample code:
echo $TERM
Output:
xterm-256color
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.
DISPLAY environment variable specifies the display device of the current X server.
Sample code:
echo $DISPLAY
Output:
:0
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.
EDITOR environment variable defines the text editor used by the current user by default.
Sample code:
echo $EDITOR
Output:
vim
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.
LD_LIBRARY_PATH environment variable specifies the path where the dynamic linker searches for shared libraries at runtime.
Sample code:
echo $LD_LIBRARY_PATH
Output:
/usr/local/lib:/usr/lib:/lib
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.
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!