리눅스 명령어 PATH설정하기
리눅스에서 명령어를 치다보면 command not found 라고 뜨는 경우가 있다.
위의 경우 명령어의 PATH가 잡혀있지 않아서 이다.
[원인]
사용자계정 추가를 위해 useradd test1 이라고 명령어를 입력했지만
root@localhost /> command not found
아래 명령어를 치면 useradd 는 adduser에 링크되어있다
root@localhost /> ls -l /usr/sbin/adduser
lrwxrwxrwx 1 root root 7 1월 1 2013 /usr/sbin/adduser -> useradd
useradd 를 입력했을때 /usr/sbin/adduser 파일을 실행해야 하는데
path가 잡혀있지 않아 명령어가 인식을 못하게 된다.
[해결]
사용자별 환경설정에서 아래와 같은경우 root 사용자만 명령어가 가능하도록 했다
root@localhost ~> ls -a
# vi .bash_profile 하고 열면 아래와 같이 path 설정이 되어있다
수정전 : PATH=$PATH:$HOME/bin
수정후 : PATH=$PATH:$HOME/bin:/usr/sbin <= 추가
위와같이 추가할경우 해당 디렉토리에 있는 실행파일을 절대경로 지정없이 어디서든 사용가능
저장후 아래 명령어 를 입력하면 적용된다.
# source .bash_profile
각 사용자별로 적용하려면 아래 파일을
~/.bash_profile
~/.bashrc
전체 사용자에게 공통으로 적용하려면 /etc 디렉토리안에
/etc/profile
/etc/bashrc