Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

A friend who owned my current Mac before me created a lot of alias commands. Is there a way to list all defined aliases and the command that is associated with them?

And if so, am I able to edit them or should I just remove them using unalias and recreate them?

share|improve this question
up vote 30 down vote accepted

All you need to do is type alias at the prompt and any active aliases will be listed.

Aliases are usually loaded at initialization of your shell so look in .bash_profile or .bashrc in your home directory.

unalias will only work for your current session. Unless you find where it is defined and loaded, it will be loaded again when you start a new Terminal session.

~/.bashrc gets run for both login and non-login shells, ~/.bash_profile only gets run for login shells.

As per comment from Chris Page:

You should put most of your customizations (including aliases) in ~/.bashrc and have ~/.bash_profile run ~/.bashrc, so they apply to both login (~/.bash_profile) and non-login (~/.bashrc) shells. Also, decide which of these should be "primary" and if the profile is your choice, tack on the rc file at the end. If the rc file is primary, source that at the beginning of your profile

These lines should be in the file ~/.bash_profile:

if [ -f "$HOME/.bashrc" ] ; then
  source $HOME/.bashrc
fi

This will include ~/.bashrc for login shells and in the order you wish if one file depends upon the other based on what you are setting.

share|improve this answer
1  
good stuff thanks - I didn't know that – MattStacey Sep 18 '11 at 19:01
1  
I recommend you put most of your customizations in ~/.bashrc and have ~/.bash_profile run ~/.bashrc, so they apply to both login (~/.bash_profile) and non-login (~/.bashrc) shells. e.g., put this in ~/.bash_profile: if [ -f "$HOME"/.bashrc ]; then . "$HOME"/.bashrc fi – Chris Page Sep 26 '11 at 13:12

You should have a look in

/etc/profile

or

~/.profile

or

~/.bash_profile

or

~/.bashrc

Which are plausible startup files for your shell (that I assumed is bash).

share|improve this answer
    
".bashrc" is the correct name of the file. – Chris Page Sep 26 '11 at 13:10
    
You're right, I don't why I wrote it like that. – Cedric H. Sep 26 '11 at 13:29
    
I would have just edited it without comment, but StackExchange wouldn't let me make a one-character edit. – Chris Page Sep 26 '11 at 13:31
    
Also check in the system-wide /etc/bashrc – EmmEff Sep 26 '11 at 19:09

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.