Notice
Recent Posts
관리 메뉴

Hacking Arts

[Linux] /etc/profile, ~/.bash_profile, /etc/bashrc, ~/.bashrc 본문

Computer & ETC/linux

[Linux] /etc/profile, ~/.bash_profile, /etc/bashrc, ~/.bashrc

Rakehell 2014. 8. 23. 02:12

/etc/profile, ~/.bash_profile, ~/.bashrc, /etc/bashrc 파일들은 장치 관리 및 사용자 환경을 위한 설정파일 입니다.

위 파일들의 차이점을 알기위해선 먼저 login shell과 non-login shell을 알아둬야 합니다.

* login shell : 처음 리눅스를 부팅하고 터미널을 켰을 경우 특정 shell로 접속이 되면 login shell

* non-login shell : 터미널을 켰을 때 특정 shell로 들어가지 않고 직접 sh 등의 명령어로 특정 shell에 들어가야 할 경우 non-login shell

예를 들어 java 환경변수를 잡을 때 non-login shell일 경우 .bashrc 파일을 이용해야 합니다.

 

* login shell (profile)

시스템에 로그인하면 login shell로 동작한다고 보면 됩니다. bash는 login shell로 동작할 때 profile을 읽습니다.

(로그인 시 /etc/profile을 먼저 읽고 이후 홈디렉토리의 ~/.profile을 읽음)

- /etc/profile

: 시스템 전역(모든 사용자)에 대한 환경설정 파일. 로그인시 설정 내용을 읽어들임. 시스템 전반적인 환경값들을 설정.

- ~/.bash_profile

: 개인 사용자에 대한 환경설정 파일. 로그인시 설정 내용을 읽어들임. 각 사용자 환경에 맞는 설정.

 

bashrc 파일을 수정해도 로그인 할 때 반영되는 이유는 /etc/profile이 /etc/bashrc 파일을 읽어오고

~/.profile이 ~/.bashrc 파일을 읽어오도록 구현되어 있기 때문입니다.

 

* interactive (rc file)

bash가 아닌 다른 shell에서 bash를 호출할 때 interactive로 동작합니다. 이 때 bash는 rc file을 읽습니다.

- /etc/bashrc

: 시스템 전역(모든 사용자)에 대한 환경설정 파일. 새로운 bash가 실행될 때 마다 내용을 읽어들임.

- ~/.bashrc

: 개인 사용자에 대한 환경설정 파일. bash가 실행될 때 마다 내용을 읽어들임.

 

/etc/profile은 부팅후에 적용되며

~/.bash_profile은 재로그인 하면 적용되나

source 명령어를 이용하여 바로 적용할 수 있습니다.

 

* CentOS 5.x 에서는 다음과 같은 순서로 읽습니다.

 

- 확인방법 : 각각 파일의 처음부분과 마지막 부분에 다음과 같이 디버깅 합니다.

echo '.bashrc start' >> /tmp/login_process.txt ## 처음부분

echo '.bashrc end' >> /tmp/login_process.txt  ## 마지막부분

/etc/profile start

/etc/profile end

.bash_profile start

.bashrc start

/etc/bashrc start

/etc/bashrc end

.bashrc end

.bash_profile end


[출처] /etc/profile, ~/.bash_profile, /etc/bashrc, ~/.bashrc|작성자 smilemoon

출처 : http://smilemoon.kr/90123354641

'Computer & ETC > linux' 카테고리의 다른 글

[Linux] /var/run/utmp, /var/log/wtmp, who(w), last  (0) 2014.08.23
[Linux] /etc/issue,/etc/issue.net,/etc/motd  (0) 2014.08.23
[Linux] 명령어 간략 모음  (0) 2014.08.23
[Linux] nohup,dmesg,col  (0) 2014.08.23
[Linux] sed  (0) 2014.08.23