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
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.
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
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.
3. USER
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.
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
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.
5. PWD
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.
6. SHELL
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.
7. TERM
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.
8. DISPLAY
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.
9. EDITOR
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.
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
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.
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!

Data recovery is always a heated topic. To successfully restore data from your device, you should know how it stores data. You can learn the difference between RAID recovery and hard drive recovery from this php.cn post.

Do you run into Word text disappearing while typing? Some letters or even paragraphs might disappear from your document. What’s wrong with it? In this post from php.cn Website, we will take a closer look at the Word automatically deleting text issue

When you are trying to log into Overwatch 2, you may receive the LC-208 error message and it prevents your game from connecting to the game servers. This post from php.cn introduces how to fix the LC-208 Overwatch error.

Generally, you can quickly access and edit Google Drive files from File Explorer. However, sometimes you may encounter the issue of “Google Drive disappeared from File Explorer”. Here this post on php.cn tells you how to get Google Drive to show up i

Why is my computer on the welcome screen for so long? How to fix Windows 7 welcome screen slow? If you still run Windows 7 on your PC and meet this issue, you are in the right place and multiple solutions will be given here by php.cn.

Want to use the built-in password management tool – Credential Manager to manage your login credentials for web and apps? How can you open Credential Manager in Windows 11? In this post, php.cn collected multiple ways to access this utility, and let’

Microsft Defender Antivirus has a feature called Periodic scanning, which can be enabled when you have installed another antivirus product on a Windows 11/10 device. Now, this post from php.cn teaches you how to enable/disable Periodic scanning on Wi

Have you ever encountered the issue of “Excel hyperlinks not working”? Do you know how to deal with it? In this post from php.cn, you can get several feasible solutions to get rid of this problem. And you will know a professional data recovery tool t


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Atom editor mac version download
The most popular open source editor

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

Zend Studio 13.0.1
Powerful PHP integrated development environment

WebStorm Mac version
Useful JavaScript development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)