Centos7:Linux环境变量配置文件

Centos7:Linux环境变量配置文件

Linux系统环境变量配置文件(按启动顺序排列注意文件位置):


(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+方向键 按块移动

发布于 2019-10-24 11:36