24

I am not finding my .bash_login and .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:~# 

Is there always only one .bashrc and .bash_profile file for every user?

And, is .bashrc and .bash_profile always found in the /home/"user name" directory?

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255

4 Answers4

21

The only ones that bash looks at by default are in the user's home directory, yes. There is also typically a single source for them in Linux -- /etc/skel. The user's home directory does not need to be under /home, though.

I see you've edited your question to ask where your .bash_login and .bash_profile files are. Based on the # prompt, I'm going to assume you're running this as root. In that case, your files are

/root/.bash_history
/root/.bashrc

See my original answer above regarding a user's home directory -- it's not always /home; in this case, root's home directory is /root.

Jeff Schaller
  • 67,283
  • 35
  • 116
  • 255
15

According to man bash:

When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and executes commands from the first one that exists and is readable.

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

~/.bashrc
    The individual per-interactive-shell startup file

There is also /etc/bashrc (/etc/bash.bashrc in Debian-based Linux) which contains System wide functions and aliases. By default, this is set, even for non-interactive, non-login shells.

EDIT:

The tilde in the paths indicates the home directory of the currently logged in user. Bash is only able to use one of ~/.bash_profile, ~/.bash_login, or ~/.profile (per currently logged in user), in that order, for reading and executing commands. (Debian-based operating systems typically do not have ~/.bash_profile or ~/.bash_login. They use the file ~/.profile. This file explains that it will be read and used unless ~/.bash_profile or ~/.bash_login are created.

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

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

10

Your bashrc file's location is distro-dependent. Here is a basic list for the system bashrc:

  • /etc/bashrc (Redhat, Fedora, etc)
  • /etc/bash.bashrc (Debian, Ubuntu, Linux Mint, Backtrack, Kali etc)
  • /etc/bash.bashrc.local (Suse, OpenSuse, etc)

Then there is the private single-user bashrc, which, for the most part is stored in ~/.bashrc for basically every distro... If you do not have one of the distros listed, or have a special system, you can always look up bashrc location on google for that distro or system...

Freddy
  • 25,565
  • Note that on SLES (at least SLES 15 where I checked), the system bashrc is /etc/bash.bashrc, which itself sources /etc/bash.bashrc.local. – philb Jan 17 '22 at 17:52
1

As people have already stated, you can find a skeleton of bashrc in /etc/skel/.bashrc. If different users want different bash configurations then you must put a .bashrc file in that users home folder.

When it comes to .bash_profile and .bash_login, the user needs to create those manually and link them via bashrc. bash_profile and bash_login exist to create a more organised feel for the different settings you load. I personally keep all of my aliases in bash_profile so I do not have to sort through a mess in bashrc to make a quick edit.

Here is an example of what you would have in your .bashrc file:

if [ -f ~/.bash_profile ]; then
        . ~/.bash_profile
fi
Peschke
  • 4,148