
(1)/etc/profile : 此檔案為系統的每個使用者設定系統環境資訊,當使用者登入時該檔案被執行。
(2)~/.bash_profile(或.profile) : 每個使用者都可使用該檔案輸入專用于自己使用的shell資訊,當使用者登入時,該檔案僅僅執行一次!預設情況下,他設定一些環境變量,執行使用者的.bashrc檔案。
(3)~/.bashrc : 該檔案包含專用于你的bash shell的bash資訊,當登入時以及每次打開新的shell時,該該檔案被讀取。
(4)/etc/bashrc : 為每一個運作bash shell的使用者執行此檔案.當bash shell被打開時,該檔案被讀取.
其他檔案
.bash_history 儲存曆史指令檔案(當使用者退出時記錄)
.bash_logout 儲存使用者退出時執行的指令
【當使用者退出時清除執行過的曆史指令 rm -rf ~/.bash_history 】
具體内容看各檔案中的注釋: /etc/profile裡# System wide environment and startup programs, for login setup
#設定在登陸時的系統全局環境和啟動程式
# Functions and aliases go in /etc/bashrc
#函數和别名在/etc/bashrc裡
# It's NOT a good idea to change this file unless you know what you
#懵逼的時候,不然不要改這個檔案
# are doing. It's much better to create a custom.sh shell script in
# /etc/profile.d/ to make custom changes to your environment, as this
最好在/etc/profile.d/中建立一個custom.sh shell腳本,友善對你的環境進行自定義更改,
# will prevent the need for merging in future updates.
#這樣做将防止在将來的更新中合并。
~/.bash_profile裡# .bash_profile
# Get the aliases and functions
取得别名和函數
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
# User specific environment and startup programs
#使用特别的環境變量和函數
PATH=$PATH:$HOME/bin
export PATH
.bashrc裡:# User specific aliases and functions
#使用者特别定義的别名和函數
# Source global definitions
#全局定義函數
/etc/bashrc 裡:# User specific aliases and functions
#使用者特别定義的别名和函數
# Source global definitions
#全局定義
具體找幾個檔案玩玩:# vim /etc/profile
加入echo ‘/etc/profile’
# vim /etc/bashrc
加入echo ‘/etc/bashrc’
# vim .bash_profile
加入echo ‘.bash_profile’
# vim .bashrc
加入echo ‘.bashrc’
#exit 退對外連結接
此時重新連結登入即可發現螢幕上輸出了echo的話
#ps
#ps -aux
在.bashrc檔案中加入 alisas ps='ps -aux'
重新連接配接後
# ps
# ps -aux
輸出相同
315 vim .bashrc
最下面加入
function hello(){
echo "$1"
echo "$2"
echo "你是最帥的!!!"
echo "$(date)"
}
#source .bashrc //重新載入檔案
#hello
輸出
你是最帥的!!!
2019年 10月 23日 星期三 10:28:54 CST
#hello q w
輸出
q
w
你是最帥的!!!
2019年 10月 23日 星期三 10:29:19 CST
用重定向的方式寫echo 'HISTTIMEFORMAT="%F %T `whoami`":' >> /etc/bashrc
【與Vim打開/etc/bashrc 寫入 HISTTIMEFORMAT="%F %T `whoami`": 一樣,之後的文章更新 >> 的講解】
.bash_history 曆史檔案
history -a 寫入硬碟曆史檔案
關于history提高效率的小操作:#!88 執行history裡的88行
#!w 執行history裡最近的以w開頭的指令
#!! 執行上一條指令
在# 按住ctrl+r 進入history 搜尋
#history 10 列出最近10條
#history -c 清除曆史記錄
#按住esc+. 上一條指令的參數
.bash_history 曆史檔案
history -a 寫入硬碟曆史檔案
Centos指令行快捷鍵:ctrl+a 光标到行首
ctrl+e 光标到行尾
ctrl+u 往前删
ctrl+d 往後删
ctrl+方向鍵 按塊移動