When you log in to a shell on a Unix system there are usually some files that are run in your home directory. You'd use these to, for example, set up aliases and additions to your $PATH.

But, how do I know exactly which file that is? How do I figure out exactly which file I need to edit (or add)?

I'm after a generic way I can use on any Unix system. Say all you have to begin with is an IP address/hostname and a username and password for an SSH login. You connect and login. Now what do you do?

  • 2
    Depends on your shell. For bash, see man bash section Invocation.
    – ott--
    Commented Feb 6, 2013 at 10:27

1 Answer 1


The profile is usually run on each login. The system-wide login file is /etc/profile and the user-specific files are usually ~/.profile. Some shells have their own profile and rc files, for example bash has .bashrc which is run by non-login bash shells and .bash_profile which is run by login bash shells. The system-wide bashrc is /etc/bash.bashrc

Thus, you would use .profile for things that should be run by login shells and .bashrc (or an equivalent) for things that should be run by non-login shells (aliases, setting up the env and similar)

bash clarification:

There are two kinds of shells: login and non-login shells. A login shell is the shell run when a user logs in. Non-login shells are all other shells. For example, when you log in via ssh or on a console, the shell you get is a login shell.

bash login shells run at startup:

  • /etc/profile
  • The first existent file of the following: ~/.bash_profile, ~/.bash_login, ~/.profile

bash non-login interactive shells run at startup:

  • /etc/bash.bashrc
  • ~/.bashrc

In some (most?) unices that come with bash, the profile sources ~/.bashrc, so ~/.bashrc is run for both login and non-login interactive shells.

If a file does not exist it is skipped.

  • So there is no way to see exactly which file(s)? I just have to sort of know what might be likely? For example in this case the shell seems to be bash and uname returns SunOS. But there is no .bash_profile or .bashrc. There are .profile, local.profile, local.login, local.cshrc. What do I use? Are the files you mention simply missing and I should create them? Or would they not be read and I need to use one of these already here? Also, what's the difference between login shells and all shells?
    – Svish
    Commented Feb 6, 2013 at 11:11
  • For bash, you would use .bashrc and .bash_profile or.profile. I do not know what local.profile, local.login and local.cshrc do, but the last one is most probably csh-specific.
    – user49740
    Commented Feb 6, 2013 at 11:15
  • So to make a "global" change to $PATH for example, I would have to add my change to both ~/.bashrc and one of ~/.bash_profile, ~/.bash_login and ~/.profile?
    – Svish
    Commented Feb 6, 2013 at 11:33
  • If "global" means "for this user", then yes. However, the profile usually sources ~/.bashrc, so adding the change to ~/.bashrc would be enough.
    – user49740
    Commented Feb 6, 2013 at 11:43

You must log in to answer this question.

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