Wie wird der vollständige Verzeichnispfad immer im Mac-Terminal angezeigt (wie Linux-Terminal)

In meinem Ubuntu-Terminal habe ich immer das aktuelle Verzeichnis vollständig angezeigt. Genau so:

Blabla@blublu:~/Musik/my_album/Klassik/beethoven$

Aber in meinem Mac (Mac OS X 10.6.5) zeigt das Terminal nicht den vollständigen Pfad an und es ist wie folgt:

Blabas-MacBook-Pro: klassische beethoven$

Gibt es überhaupt, dass ich das Verhalten des Mac-Terminals so ändere, dass es sich wie ein Linux-Terminal verhält?

Author: Der Hochstapler, 2011-01-31

6 answers

Um bash zurückkehren zu lassen "user@hostname:path/to/directory$" fügen Sie als Eingabeaufforderung die folgende Zeile zu Ihrem ~/hinzu.bash_profile:

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

Oder

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

Wenn Sie ein Leerzeichen zwischen dem $ und dem Befehl

Um die Änderungen sofort wirksam werden zu lassen, führen Sie den folgenden Befehl in jedem geöffneten Fenster aus (oder starten Sie das Terminal neu):

source ~/.bash_profile

BEARBEITEN: Eine Liste der verfügbaren Zeichenfolgen finden Sie im Absatz "AUFFORDERUNG" auf der Manpage für bash (man bash):

AUFFORDERUNG

  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
 115
Author: Asmus,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-06-15 10:41:27

Ich bin mir über Mac nicht sicher, aber in Ubuntu habe ich die Gnome Terminal Prompt mit

PS1="\a\n\n\e[31;1m\u@\h on \d at \@\n\e[33;1m\w\e[0m\n$ "
 10
Author: BZ1,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2011-02-01 05:14:21

Ich habe es CentOS Terminal auf meinem Mac sehr ähnlich gemacht. Öffnen Sie bash_profile auf Terminal

nano ~/.bash_profile

Fügen Sie Folgendes hinzu

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

Terminal neu starten und dann sieht es so aus

[email protected] [/Applications/MAMP/htdocs]$ 
 10
Author: Andres Ramos,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2016-06-09 14:30:51

Innerhalb des PS1-Werts stellt "\w" den vollständigen Pfad dar, wobei "\W" nur den aktuellen Verzeichnisnamen darstellt.

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

 6
Author: superNobody,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2011-02-01 06:27:23

Ich ändere einfach das /w in /W, um nur den aktuellen Ordner

Im Terminal

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

Kein Farbterminal

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

Ich benutze Ubuntu 16.04 und ändere die Datei in ~/.bashrc -

 1
Author: Afrijal Dzuhri,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2017-06-05 04:00:24

Wenn Sie Ihr ~/.bash_profile nicht bearbeiten möchten, können Sie auch einfach Ihr Terminal-Profil konfigurieren. Klicken Sie auf Terminal > Prefences und gehen Sie von dort zur Registerkarte Profiles und dann zur Registerkarte Shell. Aktivieren Sie [x] Run command und geben Sie export PS1='\u@\H:\w$ ' ein.

Es ist nur eine andere Art, es zu tun.

geben Sie hier die Bildbeschreibung ein

 1
Author: Stefan Falk,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/techietown.info/template/agent.layouts/content.php on line 61
2020-11-15 10:13:40