I want to cleanup my home folder and have managed to move out most of the configuration files to the .config folder. But, one file I'm not able to figure out is the .bashrc file. How can I specify bash to load .bashrc from a custom location?


3 Answers 3


The bash command accepts a --rcfile filename option that will:

Execute commands from filename (instead of ~/.bashrc) in an interactive shell.

So if you run bash --rcfile ~/.config/bashrc then you will load that file instead.

There isn't a way to configure it to load from there by default (where would you configure it?), other than recompiling it with modifications (change the definition of bashrc_file in shell.c - it's not a configuration option). You can create a wrapper that runs bash with the --rcfile option and passes all other arguments along unchanged - you'd have to add it to /etc/shells to be able to set that wrapper as your shell, and you'd have to be careful doing it. Either of those options is viable, but nontrivial to get right.

If you're on a single-user system, another option is to place all your configuration in the system-wide files in /etc, but that isn't really solving the problem. You could also have the system-wide file detect how it was run and re-execute bash with the --rcfile option automatically, but that seems even more fraught than the other approaches.

My recommendation would be to acclimatise yourself to having an extra dotfile in your home directory, but the above approaches are doable if you really can't.

  • Why isn't placing all configuration in the system-wide files in /etc solving the problem? Surely that solves it completely?
    – NeilG
    Aug 5, 2023 at 7:50

Inspired by Gnouc answer, I realized that bash reads /etc/bash.bashrc and ~/.bashrc in the same cases. Thus, you can put at the bottom of /etc/bash.bashrc:

 if [ -s "${XDG_CONFIG_HOME:-$HOME/.config}/bash/bashrc" ]; then
    . "${XDG_CONFIG_HOME:-$HOME/.config}/bash/bashrc"

and then move ~/.bashrc to $XDG_CONFIG_HOME/bash/bashrc

Bash will still attempt to load the ~/.bashrc which is not a problem since it no longer exists. And /etc/bash.bashrc will ensure that the file is loaded from your new location.


With a login shell, typically, your ~/.bash_profile contains the line:

if [ -f ~/.bashrc ]; then
    . ~/.bashrc

So you can set your own config folder here:


if [ -f "$BASHRC_CONFIG_DIR/.bashrc" ]; then
    . "$BASHRC_CONFIG_DIR/.bashrc"

For non-login shell, you can set it in /etc/bash.bashrc.

  • This will only work for a login shell (which doesn't otherwise load .bashrc). If you open an interactive shell inside a session (xterm, gnome-terminal… or you simply call bash again) it will only read ~/.bashrc and in your case would fail to load ~/.config/bash
    – Ángel
    Aug 29, 2014 at 8:22
  • @Ángel: Added it, forgot about that.
    – cuonglm
    Aug 29, 2014 at 8:29

Not the answer you're looking for? Browse other questions tagged .