리눅스 터미널과 같은 Mac 터미널에 항상 전체 디렉토리 경로를 표시하는 방법 : ~ / 음악 /

내 우분투 터미널에는 항상 현재 디렉토리가 완전히 표시되어 있습니다. 이처럼 :

blabla @ blublu : ~ / 음악 / my_album / 클래식 / 베토벤 $

그러나 내 Mac (Mac OS X 10.6.5) 터미널에는 전체 경로가 표시되지 않으며 다음과 같습니다.

blabas-MacBook-Pro : 클래식 베토벤 $

어쨌든 리눅스 터미널처럼 작동하도록 Mac 터미널 동작을 변경합니까?



답변

bash가 프롬프트로 “user @ hostname : path / to / directory $”를 반환하게하려면 ~ / .bash_profile에 다음 줄을 추가하십시오.

export PS1='\u@\H:\w$'

또는

export PS1='\u@\H:\w$ '

$와 명령 사이에 공백이 있으면

변경 사항을 즉시 적용하려면 열려있는 모든 창에서 다음 명령을 실행하십시오 (또는 터미널을 다시 시작하십시오).

source ~/.bash_profile

편집 : 사용 가능한 문자열 목록은 bash ( man bash) 매뉴얼 페이지의 “PROMPTING”단락에서 찾을 수 있습니다 .

격려

  When executing interactively, bash displays the primary prompt PS1 when it is ready to read a command, and the secondary prompt PS2 when it needs more input to complete a command.  Bash allows these prompt strings  to  be  customized  by
   inserting a number of backslash-escaped special characters that are decoded as follows:
          \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

답변

Mac에 대해서는 잘 모르겠지만 Ubuntu 에서 Gnome Terminal 프롬프트를 다음 과 같이 변경했습니다.

PS1="\a\n\n\e[31;1m\u@\h on \d at \@\n\e[33;1m\w\e[0m\n$ "


답변

내 Mac의 centOS 터미널과 매우 비슷하게 보이도록 만들었습니다. 터미널에서 bash_profile을 엽니 다

nano ~/.bash_profile

다음을 추가하십시오

# Show always fullpath on terminal
export PS1='\u@\H [\w]$ '

터미널을 다시 시작하면 다음과 같이 보입니다.

username@host.local [/Applications/MAMP/htdocs]$


답변

PS1 값에서 “\ w”는 전체 경로를 나타내고 “\ W”는 현재 디렉토리 이름 만 나타냅니다.

http://tldp.org/HOWTO/Bash-Prompt-HOWTO/bash-prompt-escape-sequences.html


답변

/ w를 / W로 변경하여 현재 폴더 만 만듭니다.

컬러 터미널에서

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ '

컬러 터미널 없음

    PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ '

우분투 16.04를 사용하고 ~ / .bashrc에서 파일을 변경합니다.


답변

이 명령을 사용했습니다. 그것은 나를 위해 작동합니다.

먼저,

vi ~/.bash_profile

그런 다음이 단어를 새 줄에 추가하십시오.

`export PS1='\u@\H:\w$ '`

드디어,

`source ~/.bash_profile`


답변