Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to manage your Linux environment variables

2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article is about how to manage your Linux environment variables. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.

Linux user environment variables can help you find the commands you need and do a lot of work without knowing the details of how the system is configured. Where these settings come from and how they are modified is another topic.

The user account configuration on the Linux system simplifies the use of the system in a variety of ways. You can run commands without knowing where they are. You can reuse previously run commands without worrying about how the system tracks them. You can check your email, check the man pages, and easily return to your home directory, regardless of where you are in the file system. And, when needed, you can adjust your account settings so that they are more in line with the way you like.

The Linux environment settings come from a series of files: some are system-wide (meaning they affect all user accounts), and some are in configuration files in your home directory. System-wide settings take effect when you log in, while local settings take effect later, so changes you make in your account will override system-wide settings. For bash users, these files contain these system files:

/ etc/environment/etc/bash.bashrc/etc/profile

And some local files:

~ / .bashrc ~ / .profile # if there is ~ / .bash_profile or ~ / .bash_login, I will not read this file ~ / .bash_profile~/.bash_login

You can modify any of the four files that exist locally because they are in your home directory and they belong to you.

Check your Linux environment settings

To view your environment settings, use the env command. Your output will probably be similar to this:

$envLS_COLORS=rs=0:di=01;34:ln=01;36:mh=00:pi=40;33:so=01;35:do=01;35:bd=40;33;01:cd=40;33;01:or=40;31;01:mi=00:su=37;41:sg=30;43:ca=30;41:tw=30;42:ow=34;42:st=37;44:ex=01;32:*.tar=01;31:*.tgz=01;31:*.arc=01;31:*.arj=01;31:*.taz=01;31:*.lha=01;31:*.lz4=01;31:*.lzh=01;31:*.lzma=01 TLZY01Trache.txztravel01TITO1THANG 31DET31DROZOLING .t7ZYO1THANG 31WOTH 31DUBZOLING 01TUBZOLING 31FOR. DZOULITY 31FOR. GZO1True 31UBG. GZO1True 31UBG. LRZOUOLY 31MUBG .lz01AND 31MUBG .xz01NT31MUBG. ZSTESTOLATE 31MUBG. TZSTENT01MUBZOLING .bz2INO1ING. Bz01ING. 31ambiguous. Jarring 01th 31purse. Warrior 01th 31purse. Warring 01th 31th. Earring 01th 31v. Sartorius 01th 31v. Rardog 01th 31v. Alzem 01mit.alzem 01th 31position. Ace01led 31position. Zoocup 01atrium. .xbm.01it.xpm.01it.xpm.01it.xpm.01mit..xpm.01it..xpmxm.01it..xpm.01it.35pur.tiff.01it.35position .png.01it.35pur.svg01it.35pur.svgz.0135position .mng.com 0135position .mngforth 035th .mngshi.mov01situ.35position .mpgwith01macular.mpegposite.35uuu.m2v01uuuuuuuu.mm035ub. .mp4veng01Every35RmvBom01Trache.flmvbent01transmission35Chang.flmvbmist01bluff35pur.flmvbmist01blating35fre.flirt01blating.flier 01blub 035fre.flv01ent35uuuu.xcf01bot 355mode.xwdd01035WOF .xcf01010135Rmvv035uv035. MKANG00OUBE 00AUTH 36RAPHY .mp3AUTATOR 36RAPHION .mpcB0OUBING 00OTERMAX 36RAPHY .RABG 0036RESION .OGOTHEOBY 0036RANFOR .OGAYOTH 00AUBING 36RNAs .opusOUS00X 36Rom .SPXOTOR 36RAPHY 36:SSH_CONNECTION=192.168.0.21 34975 192.168.0.11 22LESSCLOSE=/usr/bin/lesspipe s sLANG=en_US.UTF-8OLDPWD=/home/shsXDG_SESSION_ID=2253USER=shsPWD=/home/shsHOME=/home/shsSSH_CLIENT=192.168.0.21 34975 22XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktopSSH_TTY=/dev/pts/0MAIL=/var/mail/shsTERM=xtermSHELL=/bin/bashSHLVL=1LOGNAME=shsDBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/busXDG _ RUNTIME_DIR=/run/user/1000PATH=/home/shs/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/binLESSOPEN= | / usr/bin/lesspipe% s_=/usr/bin/env

Although you may see a lot of output, most of the * shown above are used to identify various file types using colors on the command line. When you see something like * .jpg=01;35: this tells you that the tar file will appear in red in the file list, while * .jpg=01;35: tells you that the jpg file will appear in purple. These colors are designed to make it easy to distinguish certain files from a list of files. You can learn more about the definitions of these colors and how to customize them in the "customize your colors on the Linux command line".

When you prefer an undecorated display, an easy way to turn off color display is to use the following command:

$ls-l-color=never

This command can be simply converted to an alias:

$alias ll2='ls-l-color=never'

You can also use the echo command to display a setting individually. In this command, we show the number of commands that will be remembered in the history cache:

$echo $HISTSIZE1000

If you have moved to a location, your * location in the file system will be recorded here:

PWD=/home/shsOLDPWD=/tmp makes changes

You can use a command like this to change the environment settings, but if you want to keep this setting, add a line of code, such as HISTSIZE=1234, to your ~ / .bashrc file.

What is the original meaning of a variable $export HISTSIZE=1234 "export"

Export an environment variable to enable settings to be used for your shell and possible child shell. By default, user-defined variables are local and are not exported to new processes, such as child shell and scripts. The export command makes environment variables available for use in child processes.

Add and remove variables

You can easily create new variables on the command line and sub-shell and make them available. However, these variables will disappear when you log out and come back again, unless you also add them to ~ / .bashrc or a similar file.

$export MSG= "Hello, World!"

If you want, you can use the unset command to eliminate a variable:

$unset MSG

If the variable is locally defined, you can simply set it back by loading your startup file. For example:

$echo $MSGHello, Worldwide $unset $MSG$ echo $MSG$. ~ / .bashrc$ echo $MSGHello, World! Thank you for reading! This is the end of this article on "how to manage your Linux environment variables". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it for more people to see!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report