2

I've been following tutorials to edit .profile, .bashrc and .bash_profile and I discovered that my computer has profile, bashrc and .bash_profile files instead. i.e. Only the .bash_profile file is hidden.

However, I've been able to follow these tutorials just fine, I just edit my profile file instead of .profile, and bashrc instead of .bashrc.

Is there a reason why these files are not hidden for me? And does it actually matter?

The thing I am confused about is that .profile and profile are two different files (from my understanding - e.g. I can use the touch command to create .profile and profile, then when I use the ls command to view these files, they are separate files.

So shouldn't there be an error from the terminal/bash initialisation program that's looking for .profile and .bashrc, since I only have profile and bashrc?

1
  • There are no mandatory startup files, bash will happily start up without .bashrc or .profile
  • bash doesn't read your profile or bashrc files at all.

From man bash:

FILES
   /bin/bash
          The bash executable
   /etc/profile
          The systemwide initialization file, executed for login shells
   ~/.bash_profile
          The personal initialization file, executed for login shells
   ~/.bashrc
          The individual per-interactive-shell startup file
   ~/.bash_logout
          The individual login shell cleanup file, executed when a login shell exits
   ~/.inputrc
          Individual readline initialization file

Only the executable is really needed (for obvious reasons), all the others are optional, and bash doesn't care about other files with similar names. You may get a rather limited shell if /etc/profile is missing but even then bash will start up.

  • Great explanation, thank you. Furthermore, after I spent more time reading man bash myself, I discovered this: The following paragraphs describe how bash executes its startup files. If any of the files exist but cannot be read, bash reports an error. Tildes are expanded in file names as described below under Tilde Expan- mands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, file ~/.bash_logout, if it exists. – FunP2 Jan 3 at 22:47
1

However, I've been able to follow these tutorials just fine, I just edit my profile file instead of .profile, and bashrc instead of .bashrc.

Is there a reason why these files are not hidden for me? And does it actually matter?

Yes to both questions.

Basically .bashrcbashrc

(same hold true for the other files mentioned as well)

A Unix dot-file (.filename) is treated as a hidden file. The dot preceding the filename is actually part of the filename itself; it's just interpreted by the system to be hidden.

To look at it another way, it's as if you used any other character at the beginning of the filename (a dash for example). -filename is a very different file from filename.

So, when you say you've edited your profile, your actually editing the wrong file, you need to edit your .profile.

There's an excellent post on StackOverflow that explains when to use .bashrc and .bash_profile

So shouldn't there be an error from the terminal/bash initialisation program that's looking for .profile and .bashrc, since I only have profile and bashrc?

You're not getting an error message because there's no error

  • these files are optional
  • .profile and .bashrc don't exist (see above)
  • Thank you for your answer and links to further information. Interesting how MacOS runs a login shell everytime, which is different from UNIX! – FunP2 Jan 3 at 22:56
  • It doesn't run a login shell every time...it runs an interactive non-login shell. If it was a login shell, you'd have to enter your username/password every time. macOS is not different than Unix, because it is a certified Unix – Allan Jan 3 at 23:00

You must log in to answer this question.

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