我.bash_profile在/home/user目录中的Ubuntu 14.04中找不到。我使用ls -a命令查看了.bash_profile,但是没有这样的文件。
我.bash_profile在/home/user目录中的Ubuntu 14.04中找不到。我使用ls -a命令查看了.bash_profile,但是没有这样的文件。
Answers:
Ubuntu使用~/.profile。
您可以.bash_profile在Ubuntu中创建您的文件,但.profile不会被读取。
如果我们阅读.profile内容:
cat ~/.profile
# ~/.profile: executed by the command interpreter for login shells.
# This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login
# exists.
所以用~/.profile代替~/.bash_profile
vim ~/.bashrc然后我必须编辑.bashrc . ~/.bashrc
当调用登录shell时,bash将按以下顺序查找其配置文件:
[0] ~/.bash_profile
[1] ~/.bash_login
[2] ~/.profile
找到第一个后,将停止寻找其他人,所以如果有一个.bash_profile在我$HOME的bash不会寻找.bash_login和.profile了。
在这三个文件名中,Ubuntu默认使用以下名称.profile将其重命名为.bash_profile:
mv ~/.profile ~/.bash_profile
现在,如果我们使用打开一个新的bash shell bash -l,su - $USER,sudo -u $USER -i或者运行bash作为登录shell任何其他命令,~/.bash_profile将得到采购。
到目前为止,我所说的仅适用于Bash本身,当您从GUI登录系统时,显示管理器负责提供正确的文件。
gdm3如果我们看一下,Ubuntu将用作它的显示管理器:/etc/gdm3/Xsession我们可以看到,除了.profile:
# First read /etc/profile and .profile
for file in /etc/profile "$HOME/.profile"; do
if [ -f "$file" ]; then
source_with_error_check "$file"
fi
done
因此,如果您使用GUI登录,请将该文件保留在.profile名称下,否则您可能会错过环境中的某些变量和设置。
我猜更好的选择是创建一个符号链接到.profile:
ln -s ~/.profile ~/.bash_profile
现在您的数据保存在.profile,gdm不会丢失任何东西,.bash_profile实际上是bash加载.profile,通过编辑它们中的每一个,您可以获得相同的结果。
如果您没有.profile,请从这里获取它的副本:
cp /etc/skel/.profile ~/.profile
要么
# Remember the note above
cp /etc/skel/.profile ~/.bash_profile
man bashUbuntu上的内容仍然描述了它将如何首先查找.bash_profile。
.bash_profile 首先查找找不到(因为它不存在),然后又.bash_login找不到(因为Ubuntu不使用这两个名字),最后查找,.profile是的。因此,如果创建一个.bash_profilein,~则将覆盖ubuntu ~/.profile,这是bash的默认行为,此处未做任何修改。
.bash_profile,则不会读取。我只是意识到这是因为Ubuntu不再使用“ Bash”作为GUI登录外壳。它改用“ Dash”。我认为自从18.04开始,这就是事实。
~/.profile代替~/.bash_profile我使用的最佳答案对我不起作用。
修改.bashrc工作
只是:
vim ~/.bashrc
注意:我正在使用Ubuntu WSL。
~/.profile只是默认情况下没有在ubuntu 18.04中加载
如果您的意思是.bashrc,则会在您的主文件夹中找到它。如果不存在,则可以将其从/ etc / skel文件夹复制到主文件夹。
如果您需要有关此主题的更多信息,请访问stefaan lippens页面。
~/.profile改用。