Skip to content

bash_profile과 bashrc

리눅스에서 alias를 수정하거나 PATH를 변경할때, 주로 이 네가지의 파일들을 사용한다.

/etc/profile
/etc/bashrc
~\.bash_profile
~\.bash_rc

profile

  • /etc/profile : 전역적인 파일, 모든 사용자가 로그인 시 실행
  • ~/.bash_profile : 지역적인 파일, 해당하는 사용자가 로그인 시만 실행

또한 /etc/profile의 경우 어떠한 shell이든 상관없지만, ~/.bash_profile의 경우 bash shell일 경우에만 해당된다.

Shell을 실행할 때 로그인이 필요한 Login Shell이 실헹되는 경우에 쓰인다. (ssh로 접속하거나, su 명령어로 다른계정을 들어갈 때 등이 해당된다.)

bashrc

  • /etc/bashrc : 모든 사용자가 shell을 실행시킬 때 마다 실행
  • ~/.bashrc : 해당하는 사용자가 shell을 실행시킬 때 실행

profile과 달리 Login 과정이 없으므로 shell을 실행시키는 사용자로 구분한다.

bashrc는 Non-Login Shell, Non-Login Shell 두 군데에서 모두 실행된다.

profile의 경우 대부분 환경 변수같은 것을 명시하고 bashrc의 경우 alias 같은 것을 명시한다

+----------------+-----------+-----------+------+
| |Interactive|Interactive|Script|
| |login |non-login | |
+----------------+-----------+-----------+------+
|/etc/profile | A | | |
+----------------+-----------+-----------+------+
|/etc/bash.bashrc| | A | |
+----------------+-----------+-----------+------+
|~/.bashrc | | B | |
+----------------+-----------+-----------+------+
|~/.bash_profile | B1 | | |
+----------------+-----------+-----------+------+
|~/.bash_login | B2 | | |
+----------------+-----------+-----------+------+
|~/.profile | B3 | | |
+----------------+-----------+-----------+------+
|BASH_ENV | | | A |
+----------------+-----------+-----------+------+
| | | | |
+----------------+-----------+-----------+------+
| | | | |
+----------------+-----------+-----------+------+
|~/.bash_logout | C | | |
+----------------+-----------+-----------+------+