系統和使用者的環境變數設定檔

來源:互聯網
上載者:User

標籤:系統和使用者的環境變數設定檔

用來規定環境變數的設定檔 /etc/profile,它表示系統相關的環境變數

注:不過要想改變某些環境變數的話,最好在/etc/profile.d/下面去定義,寫自己的shell 。

最好不要更改/etc/profile檔案。

比如定義個path.sh

[[email protected] ~]# vim /etc/profile.d/path.sh

#!/bin/bash

export PATH=$PATH:/tmp/:/data/bin/              #自己新定義的PATH

重設並生效

[[email protected] ~]# source /etc/profile

[[email protected] ~]# echo $PATH

/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin:/tmp/:/data/bin/

另外一個設定檔/etc/bashrc,會定義PS1,umask(/etc/profile檔案裡也有定義)

注:這個檔案最好也不要修改;最好在/etc/profile.d/下面去定義,寫自己的shell


查看PS1

[[email protected] ~]# echo $PS1         #PS1定義的我們命令的首碼

[\[email protected]\h \W]\$

修改PS1,把W換成w,區別就是w會顯示絕對路徑,而W會顯示路徑的最後一段

[[email protected] ~]# PS1=‘[\[email protected]\h \w]\$ ‘

[[email protected] ~]# cd /etc/init.d/

[[email protected] /etc/init.d]#

[[email protected] /etc/init.d]# PS1=‘[\[email protected]\h \W]\$ ‘

[[email protected] init.d]# cd /etc/init.d/

[[email protected] init.d]#

還可以加上時間\t

[[email protected] init.d]# PS1=‘[\[email protected]\h\t \W]\$ ‘

[[email protected]19:29:31 init.d]#

root使用者是#   普通使用者是$

[[email protected] ~]# su - wyy

[[email protected] ~]$


/etc/profile、/etc/bashrc是關於系統層級的。除了這兩個之外,還有一些在使用者的家目錄下,可以用 ls -la .

可以看到有幾個以.bash開頭的。 .bash_profile檔案和我們系統的/etc/profile檔案是一類檔案,很像。/etc/profile

作一個全域的,任何使用者都能用到的這樣的一個設定檔;若想針對使用者自己來定義一些環境變數,可以在這個

.bash_profile裡去定義。

.bashrc這個裡面會定義使用者的別名,當使用者登入時以及每次開啟新的shell時執行該檔案。


注: .bashrc會被.bash_profile調用

          如果在.bashrc裡面定義了變數,然後又在.bash_profile裡面unset該變數,那麼當我們登入一個終端時,echo該變數的值為空白


本文出自 “linux” 部落格,轉載請與作者聯絡!

系統和使用者的環境變數設定檔

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.