How to manage your Linux environment variables

Linux user environment variables can help you find the command you need, without knowing the details of how to configure the system to complete a lot of work. These settings where they come from and how they are modified is another topic.

Linux user account on the system configuration simplifies use of the system in several ways. You can run the command without the need to know their location. You can re-use the command previously run, but do not worry about how the system is to track them. You can check your e-mail, see the man pages, and easily return to your home directory, but do not control where you are in the file system. And, when needed, you can adjust your account settings so that it more in line with the way you like.

Linux environment settings file from a range of: some system-wide (meaning they affect all user accounts), some of which are in your home directory configuration file. System-wide settings take effect when you log in, and local settings to take effect thereafter, so changes you make in your account to cover system-wide settings. For bash users, these files contain these system files:

/etc/environment
/etc/bash.bashrc
/etc/profile
复制代码

As well as some of the local file:

~/.bashrc
~/.profile # 如果有 ~/.bash_profile 或 ~/.bash_login 就不会读此文件
~/.bash_profile
~/.bash_login
复制代码

You can modify any of the four files exist locally, because they are in your home directory, and they are yours.

Check your Linux environment settings

To see your environment settings, use the envcommand. Your output will likely be similar to this:

$ env
LS_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;31:*.tlz=01;31:*.txz=01;31:*.tzo=01;31:*.t7z=01;31:*.zip=01;31:
*.z=01;31:*.Z=01;31:*.dz=01;31:*.gz=01;31:*.lrz=01;31:*.lz=01;31:*.lzo=01;31:*.xz=01;
31:*.zst=01;31:*.tzst=01;31:*.bz2=01;31:*.bz=01;31:*.tbz=01;31:*.tbz2=01;31:*.tz=01;31:
*.deb=01;31:*.rpm=01;31:*.jar=01;31:*.war=01;31:*.ear=01;31:*.sar=01;31:*.rar=01;31:
*.alz=01;31:*.ace=01;31:*.zoo=01;31:*.cpio=01;31:*.7z=01;31:*.rz=01;31:*.cab=01;31:
*.wim=01;31:*.swm=01;31:*.dwm=01;31:*.esd=01;31:*.jpg=01;35:*.jpeg=01;35:*.mjpg=01;35:
*.mjpeg=01;35:*.gif=01;35:*.bmp=01;35:*.pbm=01;35:*.pgm=01;35:*.ppm=01;35:*.tga=01;35:
*.xbm=01;35:*.xpm=01;35:*.tif=01;35:*.tiff=01;35:*.png=01;35:*.svg=01;35:*.svgz=01;35:
*.mng=01;35:*.pcx=01;35:*.mov=01;35:*.mpg=01;35:*.mpeg=01;35:*.m2v=01;35:*.mkv=01;35:
*.webm=01;35:*.ogm=01;35:*.mp4=01;35:*.m4v=01;35:*.mp4v=01;35:*.vob=01;35:*.qt=01;35:
*.nuv=01;35:*.wmv=01;35:*.asf=01;35:*.rm=01;35:*.rmvb=01;35:*.flc=01;35:*.avi=01;35:
*.fli=01;35:*.flv=01;35:*.gl=01;35:*.dl=01;35:*.xcf=01;35:*.xwd=01;35:*.yuv=01;35:
*.cgm=01;35:*.emf=01;35:*.ogv=01;35:*.ogx=01;35:*.aac=00;36:*.au=00;36:*.flac=00;36:
*.m4a=00;36:*.mid=00;36:*.midi=00;36:*.mka=00;36:*.mp3=00;36:*.mpc=00;36:*.ogg=00;36:
*.ra=00;36:*.wav=00;36:*.oga=00;36:*.opus=00;36:*.spx=00;36:*.spf=00;36:
SSH_CONNECTION=192.168.0.21 34975 192.168.0.11 22
LESSCLOSE=/usr/bin/lesspipe %s %s
LANG=en_US.UTF-8
OLDPWD=/home/shs
XDG_SESSION_ID=2253
USER=shs
PWD=/home/shs
HOME=/home/shs
SSH_CLIENT=192.168.0.21 34975 22
XDG_DATA_DIRS=/usr/local/share:/usr/share:/var/lib/snapd/desktop
SSH_TTY=/dev/pts/0
MAIL=/var/mail/shs
TERM=xterm
SHELL=/bin/bash
SHLVL=1
LOGNAME=shs
DBUS_SESSION_BUS_ADDRESS=unix:path=/run/user/1000/bus
XDG_RUNTIME_DIR=/run/user/1000
PATH=/home/shs/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
LESSOPEN=| /usr/bin/lesspipe %s
_=/usr/bin/env
复制代码

While you may see a lot of output, shown above for most of the first to use color to identify various file types on the command line. When you see something like *.tar=01;31:this stuff, which tells you tarthe file will be displayed in red in the file list, however, *.jpg=01;35:tell you a jpg file will show up purple. These colors are intended to make it easier to distinguish certain files from a file list. You can " in the Linux command line to customize your color " to learn more about these colors is defined at and how to customize them.

Simple method when you prefer a more decorative display without a color display is turned off using the following command:

$ ls -l --color=never
复制代码

This command can be easily converted to an alias:

$ alias ll2='ls -l --color=never'
复制代码

You can also use echocommands to separately show a setting. In this command, we show the number in the history buffer is memory command:

$ echo $HISTSIZE
1000
复制代码

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

PWD=/home/shs
OLDPWD=/tmp
复制代码

Make changes

You can change the environment settings using a command like this, but if you want to keep this setting, you ~/.bashrcadd a line of code file, for example HISTSIZE=1234.

$ export HISTSIZE=1234
复制代码

What is the intention of "export" is a variable

Exporting can set an environment variable for your shell and possible sub-shell. By default, user-defined variable is local, not be exported to a new process, for example, sub-shell and scripting. exportCommand causes the environment variables are available to perform their functions in the child process.

Add and remove variables

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

$ export MSG="Hello, World!"
复制代码

If you want, you can use the unsetcommand to eliminate one variable:

$ unset MSG
复制代码

If the variable is locally defined, you can load your startup files simply set it back. E.g:

$ echo $MSG
Hello, World!
$ unset $MSG
$ echo $MSG

$ . ~/.bashrc
$ echo $MSG
Hello, World!
复制代码

summary

User account is a set of appropriate startup file set up to create a useful user environment, individual users and system administrators can edit their personal settings file (for users) or many files from the set origin (for The system administrator) to change the default settings.


via: www.networkworld.com/article/338…

Author: Sandra Henry-Stocker topics: lujun9972 Translator: robsean proofread: wxy

This article from the LCTT original compiler, Linux China is proud

Guess you like

Origin blog.csdn.net/weixin_34114823/article/details/91405943