在 CentOS(以及大多数 Linux 系统)中,查看全部环境变量常用下面几种方式:
env
或
printenv
两者都会列出当前 shell 的所有环境变量。
set
set会显示所有变量(环境变量 + 普通 shell 变量 + 函数),内容比env多。
echo $PATH
printenv PATH
export
显示当前通过
export导出的变量(通常和env差不多)。
环境变量通常在这些文件中定义:
/etc/profile/etc/profile.d/*.sh/etc/bashrc~/.bash_profile~/.bashrc~/.bash_export查看示例:
cat ~/.bashrc
cat /etc/profile
cat /proc/<pid>/environ
例如:
cat /proc/1/environ | tr '\0' '\n'
✅ 总结
env 或 printenvset.bashrc / .bash_profile / /etc/profile如果你是 CentOS 7 / 8 / Stream,以上命令都通用。需要我帮你分析某个具体变量或环境问题也可以说。