0

I want to create a alias of my cd command. I have created the .bashrc file and append the command cd ...... to it. (Since the file was newly created, it just has this one line that I added).

After that, only after I typed . ~/.bashrc, can the alias works. If I close the terminal and open it again, I need to retype . ~/.bashrc.

It's really annoying to do this every time. Is there any way to solve this problem?

Thank you so much for help

mlwn
  • 1,156
  • 1
  • 10
  • 25
Xiaojian
  • 149
  • 1
  • 1
  • 6

2 Answers2

3

When you login to linux system, only ~/.profile will be called:

$ cat ~/.profile

# if running bash
if [ -n "$BASH_VERSION" ]; then
    # include .bashrc if it exists
    if [ -f "$HOME/.bashrc" ]; then
    . "$HOME/.bashrc"
    fi
fi

You need to source ~/.bashrc inside ~/.profile manaully. Read this to learn more.


EDIT:

If you're using iTerm2 on mac, it actually start a login shell by default when open tabs.
But you can change it: Preferences > General > Command

Community
  • 1
  • 1
kev
  • 155,172
  • 47
  • 273
  • 272
  • My answer [here](http://superuser.com/a/636221/107862) also has some relevant information about shell startup files. But as @BroSlow indicates if this is a normal interactive shell then this shouldn't be the problem. – Etan Reisner Sep 17 '14 at 02:01
2

If using OS X, append the alias to ~/.bash_profile.

You could also add alias to ~/.bashrc, then add source ~/.bashrc to ~/.bash_profile.

Better yet, put all your aliases in ~/.aliases, and source it in ~/.bash_profile.

By default, OS X first sources /etc/bashrc (which shouldn't be modified unless absolutely necessary), then sources the user's ~/.bash_profile at the start of every interactive session.

John B
  • 3,566
  • 1
  • 16
  • 20