天天看點

Linux常用環境變量 PATH、PS1、LANG語系變量 介紹

1、PATH

Linux常用環境變量 PATH、PS1、LANG語系變量 介紹

2、PS1變量:指令提示符設定

Linux常用環境變量 PATH、PS1、LANG語系變量 介紹
Linux常用環境變量 PATH、PS1、LANG語系變量 介紹

3、LANG語系變量

關于Linux能支援中文的兩個前提條件:

1)安裝了中文字型和編碼

2)操作終端必須支援中文編碼

舉例:

LANG語系變量為en_US.UTF-8時,代表英文語言環境,字元編碼是utf8格式

[root@localhost ~]# echo $LANG
en_US.UTF-8
           

使用 --help時顯示的是英文幫助,比如:tail --help

[root@localhost ~]# tail --help
Usage: tail [OPTION]... [FILE]...
Print the last 10 lines of each FILE to standard output.
With more than one FILE, precede each with a header giving the file name.
With no FILE, or when FILE is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.
  -c, --bytes=K            output the last K bytes; alternatively, use -c +K
                           to output bytes starting with the Kth of each file
  -f, --follow[={name|descriptor}]
                           output appended data as the file grows;
                           -f, --follow, and --follow=descriptor are
                           equivalent
  -F                       same as --follow=name --retry
  -n, --lines=K            output the last K lines, instead of the last 10;
                           or use -n +K to output lines starting with the Kth
      --max-unchanged-stats=N
                           with --follow=name, reopen a FILE which has not
                           changed size after N (default 5) iterations
                           to see if it has been unlinked or renamed
                           (this is the usual case of rotated log files).
                           With inotify, this option is rarely useful.
      --pid=PID            with -f, terminate after process ID, PID dies
  -q, --quiet, --silent    never output headers giving file names
      --retry              keep trying to open a file even when it is or
                             becomes inaccessible; useful when following by
                             name, i.e., with --follow=name
  -s, --sleep-interval=N   with -f, sleep for approximately N seconds
                             (default 1.0) between iterations.
                           With inotify and --pid=P, check process P at
                           least once every N seconds.
  -v, --verbose            always output headers giving file names
      --help     display this help and exit
      --version  output version information and exit
[root@localhost ~]# 
           

LANG語系變量為zh_CN.UTF-8時,代表中文語言環境,字元編碼是utf8格式

[root@localhost tmp]# echo $LANG      
zh_CN.UTF-8
[root@localhost tmp]#
           

使用 --help時顯示的是中文幫助(前提安裝了中文字型和編碼),比如:tail --help

[root@localhost tmp]# tail --help
用法:tail [選項]... [檔案]...
顯示每個指定檔案的最後10 行到标準輸出。
若指定了多于一個檔案,程式會在每段輸出的開始添加相應檔案名作為頭。
如果不指定檔案或檔案為"-" ,則從标準輸入讀取資料。

長選項必須使用的參數對于短選項時也是必需使用的。
  -c, --bytes=K         輸出最後K 位元組;另外,使用-c +K 從每個檔案的
                        第K 位元組輸出
  -f, --follow[={name|descriptor}]
                即時輸出檔案變化後追加的資料。
                        -f, --follow 等于--follow=descriptor 
  -F            即--follow=name --retry
  -n, --lines=K            output the last K lines, instead of the last 10;
                           or use -n +K to output lines starting with the Kth
      --max-unchanged-stats=N
                           with --follow=name, reopen a FILE which has not
                           changed size after N (default 5) iterations
                           to see if it has been unlinked or renamed
                           (this is the usual case of rotated log files).
                           With inotify, this option is rarely useful.
      --pid=PID         同 -f 一起使用,當 PID 所對應的程序死去後終止
  -q, --quiet, --silent 不輸出給出檔案名的頭
      --retry           即使目标檔案不可通路依然試圖打開;在與參數
                        --follow=name 同時使用時常常有用。
  -s, --sleep-interval=N   with -f, sleep for approximately N seconds
                             (default 1.0) between iterations.
                           With inotify and --pid=P, check process P at
                           least once every N seconds.
  -v, --verbose            always output headers giving file names
      --help            顯示此幫助資訊并退出
      --version         顯示版本資訊并退出
           

那麼linux到底支援多少語系呢?

我們可以使用以下指令查詢:locale -a

locale -a:檢查linux支援哪些語系,裝沒裝是另一回事

[[email protected] tmp]# locale -a|wc -l
735
           

可以看出:這個版本的Linux支援735中語系,太多了就不一一列舉了

locale :檢視本地linux已經裝了的語系

[[email protected] tmp]# locale
LANG=zh_CN.UTF-8
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC="zh_CN.UTF-8"
LC_TIME="zh_CN.UTF-8"
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY="zh_CN.UTF-8"
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER="zh_CN.UTF-8"
LC_NAME="zh_CN.UTF-8"
LC_ADDRESS="zh_CN.UTF-8"
LC_TELEPHONE="zh_CN.UTF-8"
LC_MEASUREMENT="zh_CN.UTF-8"
LC_IDENTIFICATION="zh_CN.UTF-8"
LC_ALL=
[[email protected] tmp]# 
           

我們還要通過檔案 /etc/sysconfig/i18n 定義系統的預設語系,檢視這個檔案的内容:

[[email protected] tmp]# cat /etc/sysconfig/i18n
LANG="en_US.UTF-8"
SYSFONT="latarcyrheb-sun16"
[[email protected] tmp]# 
           

所謂的預設語系就是指下次重新開機之後系統所使用的語系

所謂的目前系統語系是指目前系統正在使用的語系(可以了解為臨時生效的) ,

如果系統重新開機,會從預設語系配置檔案/etc/sysconfig/i18n中讀取語系,然後賦予變量LANG讓這個語系生效,也就是說LANG定義的語系隻對目前系統生效,要想永久生效就要修改/etc/sysconfig/i18n這個檔案了。

Linux常用環境變量 PATH、PS1、LANG語系變量 介紹
Linux常用環境變量 PATH、PS1、LANG語系變量 介紹

繼續閱讀