Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I have a one-line .bashrc file in my home directory:

alias countlines='find . -type f -print0 | xargs -0 cat | wc -l'

But it is not creating the alias. Why might that be?

share|improve this question

5 Answers 5

up vote 24 down vote accepted

In OSX, .bash_profile is used instead of .bashrc.

And yes, the .bash_profile file should be located in /Users/YourName/
(In other words, ~/.bash_profile)

For example, /Users/Aaron/.bash_profile

share|improve this answer
7  
This is not the right answer. Aliases are not inherited, so, if you only define them in .bash_profile, they won't be defined in non-login shells (eg when you run bash inside bash). –  LaC Feb 13 '11 at 18:49
    
Or one can use bash_aliases which has the same effect as putting the aliases in bashrc, but more manageable: ss64.com/osx/syntax-bashrc.html –  Atul Ingle Dec 10 '13 at 13:22

.[bash_]profile and .bashrc can be used on both OS X and Linux. The former is loaded when the shell is a login shell; the latter when it is not. The real difference is that Linux runs a login shell when the user logs into a graphical session, and then, when you open a terminal application, those shells are non-login shells; whereas OS X does not run a shell upon graphical login, and when you run a shell from Terminal.app, that is a login shell.

If you want your aliases to work in both login and non-login shells (and you usually do), you should put them in .bashrc and source .bashrc in your .bash_profile, with a line like this:

[ -r ~/.bashrc ] && source ~/.bashrc

This applies to any system using bash.

share|improve this answer
7  
+1 with the caveat that everything in .bashrc will be run again for sub-shells (and subsub-, subsubsub-, etc), so e.g. PATH=$PATH:/my/private/binaries will lead to PATH bloat. See this for a workaround. –  Gordon Davisson Feb 12 '11 at 18:51
2  
True. Since exported instance variables are inherited, I just set them in .profile instead of .bashrc. –  LaC Feb 13 '11 at 11:28
    
@LaC can you explain _Since exported instance variables are inherited, I just set them in .profile_…? –  sam Jan 14 at 18:11
1  
@sam, I don't know where "instance" came from. I just meant "exported variables". Unfortunately I cannot edit that comment. –  LaC Jan 15 at 6:35

Or create a sym link called .bash_profile pointed at your .bashrc

ln -s .bashrc .bash_profile
share|improve this answer

It is not being aliased because .bash_profile is used instead of .bashrc on Mac OS X.

So you have two options:

  • Put the alias in your ~/.bash_profile

  • Or source your .bashrc from your .bash_profile by adding this line to the .bash_profile:

    . ~/.bashrc

share|improve this answer

You may use su to login as root user. But su is unmodified SHELL environment,so the .bashrc does not work. You could use: su - to do this.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.