3

To speed up some of my Linux commands, I followed the recommendations of this Lifehacker article by writing aliases to quickly cd into folders I like. Fran's answer to "source" the .bashrc file by executing this line enabled me to use my shortcuts:

. ~/.bashrc

Like the OP in this post, it is unclear to me how to always access my shortcuts without having to rerun that command.

Community
  • 1
  • 1
NumenorForLife
  • 1,736
  • 8
  • 27
  • 55
  • Whether or not the .bashrc gets loaded will depend on your shell and how your login is setup. Are you using Linux or OSX? Which Linux distribution ?You may need to source .bashrc inside of .profile or inside of .bash_profile. – Michael Berkowski Jun 01 '15 at 12:58
  • This is more on topic over at http://superuser.com – Michael Berkowski Jun 01 '15 at 12:59

2 Answers2

3

This is an issue lots of people run into when new to Bash. It comes from not understanding which files are read when.

Your .profile or .bash_profile is read when you log on. This is a login shell.

Your .bashrc is run whenever you start another interactive shell.

Typically you will want to include a source ~/.bashrc as the last thing that happens in your profile to ensure that your login shell has these same aliases.

David Hoelzer
  • 15,862
  • 4
  • 48
  • 67
1

Per the bash man page:

When an interactive shell that is not a login shell is started, bash reads and executes commands from ~/.bashrc, if that file exists.

Therefore, every time you open a new interactive bash shell (such as when you open a new terminal), ~/.bashrc will automatically be read.

unutbu
  • 842,883
  • 184
  • 1,785
  • 1,677