terminal을 실행시켰을 때, 기본적으로 보여지는 shell prompt는 username와 hostname정도를 보여준다. 작업을 하다보니, shell prompt에 현재 경로와 시간을 표시해주니 편리하여 방법을 적봅니다.
shell prompt를 변경하는 방법은 PS1 환경변수를 이용하면 된다. 아래와 같은 방법으로 shell prompt를 바로 변경할 수 있다.
위 방법은 환경 변수를 바로 변경하여 shell prompt가 변경되는 것을 바로 확인 할 수 있다. 원하는 옵션을 찾을 때는 이 방법을 사용하면된다. 허나 위방법은 terminal이 다시 시작되면 설정이 날라가 버린다. terminal이 실행될 때, PS1의 환경 변수를 설정하려면 아래의 방법처럼 .bashrc파일에 PS1의 옵션을 지정해주면 된다. source파일은 환경설정을 바로 적용하기 위해 사용하였다.
위의 export
PS1='[\t]\w>' 옵션이 본인이 사용하는 옵션이다. 현재 시간과 현재 경로를 표시해주고 있어서 작업하기가 수월하다.
사용가능한 옵션
\a : an ASCII bell character (07) \d : the date in “Weekday Month Date” format (e.g., “Tue May 26”) \D{format} : the format is passed to strftime(3) and the result is inserted into the prompt string; an empty format results in a locale-specific time representation. The braces are required \e : an ASCII escape character (033) \h : the hostname up to the first ‘.’ \H : the hostname \j : the number of jobs currently managed by the shell \l : the basename of the shell’s terminal device name \n : newline \r : carriage return \s : the name of the shell, the basename of $0 (the portion following the final slash) \t : the current time in 24-hour HH:MM:SS format \T : the current time in 12-hour HH:MM:SS format \@ : the current time in 12-hour am/pm format \A : the current time in 24-hour HH:MM format \u : the username of the current user \v : the version of bash (e.g., 2.00) \V : the release of bash, version + patch level (e.g., 2.00.0) \w : the current working directory, with $HOME abbreviated with a tilde \W : the basename of the current working directory, with $HOME abbreviated with a tilde \! : the history number of this command \# : the command number of this command \$ : if the effective UID is 0, a #, otherwise a $ \nnn : the character corresponding to the octal number nnn \\ : a backslash \[ : begin a sequence of non-printing characters, which could be used to embed a terminal control sequence into the prompt \] : end a sequence of non-printing characters