Linux 中的 .bashrc 文件在哪里?

22 bash profile bashrc kali-linux

我没有找到我的 .bash_login 和 .bash_profile

root@linux:~# locate .bash*
/etc/bash.bashrc
/etc/skel/.bashrc
/etc/skel/.bashrc.original
/home/noroot/.bashrc
/home/noroot/.bashrc.original
/root/.bash_history
/root/.bashrc
/usr/share/base-files/dot.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/bash.bashrc
/usr/share/doc/adduser/examples/adduser.local.conf.examples/skel/dot.bashrc
/usr/share/kali-defaults/.bashrc
root@linux:~# 
Run Code Online (Sandbox Code Playgroud)

每个用户总是只有一个 .bashrc 和 .bash_profile 文件吗?

而且, .bashrc 和 .bash_profile 总是在 /home/"user name" 目录中找到吗?

Jef*_*ler 20

bash 在默认情况下唯一查看的是在用户的主目录中,是的。在 Linux 中,它们通常也有一个单一的来源——/etc/skel。但是,用户的主目录不需要在 /home 下。

我看到你编辑了你的问题来询问你的 .bash_login 和 .bash_profile 文件在哪里。根据#提示,我将假设您以 root 身份运行它。在这种情况下,您的文件是

/root/.bash_history
/root/.bashrc
Run Code Online (Sandbox Code Playgroud)

请参阅我上面关于用户主目录的原始答案——它并不总是 /home;在这种情况下,root 的主目录是/root.


Tim*_*tin 15

根据man bash

当 bash 作为交互式登录 shell 或作为具有 --login 选项的非交互式 shell 调用时,它首先从文件 /etc/profile 读取并执行命令(如果该文件存在)。读取该文件后,它会按顺序查找 ~/.bash_profile、~/.bash_login 和 ~/.profile,然后从第一个存在且可读的命令中读取和执行命令。

~/.bash_profile
    The personal initialization file, executed for login shells

~/.bashrc
    The individual per-interactive-shell startup file
Run Code Online (Sandbox Code Playgroud)

还有/etc/bashrc/etc/bash.bashrc在基于 Debian 的 Linux 中)包含System wide functions and aliases. 默认情况下,即使对于非交互式、非登录 shell,也是如此。

编辑:

tilde在路径表示home directory的用户当前登录。Bash 只能~/.bash_profile, ~/.bash_login, or ~/.profile按顺序使用(每个当前登录的用户)之一来读取和执行命令。(基于 Debian 的操作系统通常没有~/.bash_profile or ~/.bash_login. 他们使用的文件~/.profile。该文件说明除非~/.bash_profile or ~/.bash_login创建,否则它将被读取和使用。

#~/.profile: executed by the command interpreter for login shells.

#This file is not read by bash(1), if ~/.bash_profile or ~/.bash_login 存在。


Int*_*... 8

您的bashrc文件位置取决于发行版。这是系统的基本列表bashrc

  • /etc/bashrc (红帽、Fedora 等)
  • /etc/bash.bashrc (Debian、Ubuntu、Linux Mint、Backtrack、Kali 等)
  • /etc/bash.bashrc.local (Suse、OpenSuse 等)

然后是 private single-user bashrc,其中大部分存储在~/.bashrc基本上每个发行版中...如果您没有列出其中一个发行版,或者有一个特殊的系统,您可以随时bashrc在 google 上查找位置对于那个发行版或系统...