linux的环境变量怎么看

49次阅读
没有评论

共计 2198 个字符,预计需要花费 6 分钟才能阅读完成。

今天丸趣 TV 小编给大家分享一下 linux 的环境变量怎么看的相关知识点,内容详细,逻辑清晰,相信大部分人都还太了解这方面的知识,所以分享这篇文章给大家参考一下,希望大家阅读完这篇文章后有所收获,下面我们一起来了解一下吧。

linux 环境变量有两个位置:1、“/etc”目录下的 bashrc、profile 和 environment 文件,文件内是已经配置好的环境变量;2、用户目录下的“.bashrc”和“.bash_profile”文件,这两个文件是都是隐藏文件。

本教程操作环境:linux7.3 系统、Dell G3 电脑。

linux 的环境变量在哪里

1、系统位置,/etc 目录下的 bashrc、profile、environment 三个文件

2、用户目录(root 或普通用户)下的.bashrc、.bash_profile 两个文件,注意这两个文件前面都有点,是隐藏文件。

先说这 3 个系统文件,列出文件内容(参考 CentOS7)。/**/ 为添加注释

# /etc/bashrc
# System wide functions and aliases /*  系统广泛功能(函数)和别名  */
# Environment stuff goes in /etc/profile /*  环境东西(环境变量)在 /etc/profile 文件中  */
/*  修改这个文件不是一个好主意,除非你知道自己在干什么。*/
/*  在 /etc/profile.d/ 目录下创建一个自定义脚本会是修改环境变量的更好方法  */
/*  但是会阻止在将来更新时合并的需要  */
# 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
# will prevent the need for merging(合并) in future updates.
……………………………………………………………………
……………………………………………………………………
……………………………………………………………………
# /etc/profile
# System wide environment and startup programs, for login setup
# Functions and aliases go in /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
# will prevent the need for merging in future updates.
……………………………………………………………………
……………………………………………………………………
……………………………………………………………………

第三个文件 environment 文件打开是一个空文件,不表。

再说两个用户文件,贴上文件内容(参考 CentOS7)/**/ 为添加注释

普通用户:

root 用户

# .bashrc
# User specific aliases and functions /*  用户指定的别名和函数(功能)*/
alias rm= rm -i 
alias cp= cp -i 
alias mv= mv -i 
# Source global definitions
if [ -f /etc/bashrc ]; then
. /etc/bashrc
# .bash_profile
# Get the aliases and functions /*  获取别名和函数(功能)*/
if [ -f ~/.bashrc ]; then
. ~/.bashrc
# User specific environment and startup programs /*  用户指定环境变量和启动程序(linux 开机启动程序放在这里?还没有试过) */
PATH=$PATH:$HOME/bin
export PATH

这几个文件的注释已经说得很清楚了,bashrc 文件是 用户指定别名和函数(功能),bash_profile 文件是用来获取 bashrc 文件中的别名和函数(功能),用户还可以在此文件中指定环境变量和开机启动程序。在系统的 bashrc、和 bash_profile 文件明确说明 在 /etc/profile.d/ 目录下创建一个自定义脚本会是修改环境变量的更好方法。如图:

以上就是“linux 的环境变量怎么看”这篇文章的所有内容,感谢各位的阅读!相信大家阅读完这篇文章都有很大的收获,丸趣 TV 小编每天都会为大家更新不同的知识,如果还想学习更多的知识,请关注丸趣 TV 行业资讯频道。

正文完
 
丸趣
版权声明:本站原创文章,由 丸趣 2023-08-03发表,共计2198字。
转载说明:除特殊说明外本站除技术相关以外文章皆由网络搜集发布,转载请注明出处。
评论(没有评论)