~/.bashrc, ~/.bash_login, ~/.bash_logout, ~/.bash_profile, ~/.profile,/etc/profile,/etc/bash.bashrc,/etc/ssh/ssh_config 有什么区别和 sshd_config,它们何时加载以及它们的用途是什么?
最佳答案
bash 的手册页说有以下 bash shell 的初始化文件:
/etc/profile
The systemwide initialization file, executed for login shells
/etc/bash.bashrc
The systemwide per-interactive-shell startup file
/etc/bash.bash.logout
The systemwide login shell cleanup file, executed when a login shell exits
~/.bash_profile
The personal initialization file, executed for login shells
~/.bashrc
The individual per-interactive-shell startup file
~/.bash_logout
The individual login shell cleanup file, executed when a login shell exits
~/.inputrc
Individual readline initialization file
显然,不同的 shell(bash、zsh、csh 等)似乎有不同的配置文件。 shell 似乎与不同的 linux 和 unix 版本一样多:csh、ksh、bash、zsh、... Bash 有一个 .bashrc
,Zsh 有一个 .zshrc
等等。还可以区分登录 shell 和非登录 shell,以及系统范围的默认值和用户特定的默认值。
区分login 和non-login shell 是有意义的,因为有些命令应该只在登录时处理,而其他命令应该在每次打开新的 shell 时运行终端窗口。这就是 .bash_profile and .bashrc 之间的区别.对于 bash,.bashrc
会在您每次启动新的 bash 副本时重新加载,即当您启动新的 bash 但未登录时。 .bash_profile
或 .profile
仅在您登录时加载。 bashrc 中的缩写 rc 代表“运行命令”或“运行控制”,是从旧的 Unix 系统采用的约定。
系统范围的默认值......
/etc/profile
..login shell,用于带登录的交互式 shell/etc/bashrc
..非登录 Bash shells
主目录中的用户特定默认值 ~ for..
~/.profile
..登录 shell,登录后调用~/.bashrc
..非登录 shell,如果已经登录~/.bash_profile
..login shell,在登录后调用(低优先级)
用于登录和注销的主目录中用户特定的默认值
~/.bash_login
..登录 shell(登录时调用)~/.bash_logout
..登录 shell(在注销时调用)
以下链接很有帮助:.bashrc vs .bashprofile和 .bash_profile vs .bashrc , bash manual page (man bash)和 Zsh/Bash startup files loading order (.bashrc, .zshrc etc.) .
关于bash - 各种 shell 配置文件之间有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6372751/