In my ubuntu terminal I have always current directory shown completely. Just like this:
blabla@blublu:~/music/my_album/classical/beethoven$
But in my Mac (Mac OS X 10.6.5) terminal does not show the full path and it is like this:
blabas-MacBook-Pro:classical beethoven$
Is there anyway that I change mac terminal behavior to act like linux terminal?
27 Answers
To let bash return "user@hostname:path/to/directory$" as your prompt, add the following line to your ~/.bash_profile:
export PS1='\u@\H:\w$'or
export PS1='\u@\H:\w$ 'if you like having a space between the $ and the command
to make the changes take effect immediately, run the following command in every open window (or restart Terminal):
source ~/.bash_profileEDIT:
A list of available strings can be found in the paragraph "PROMPTING" in the man page for bash (man bash):
7PROMPTING
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
I made it to look very similar to centOS terminal on my Mac. Open bash_profile, on terminal
nano ~/.bash_profileAdd the following
# Show always fullpath on terminal
export PS1='\u@\H [\w]$ 'Restart Terminal and then it will looks like this
[/Applications/MAMP/htdocs]$ I am not sure about Mac, but in Ubuntu I've changed the Gnome Terminal prompt with
PS1="\a\n\n\e[31;1m\u@\h on \d at \@\n\e[33;1m\w\e[0m\n$ " 0 Inside PS1 value, "\w" represents the full path, where "\W" represents the current directory name only.
1If you don't want to edit your ~/.bash_profile you can also just configure your terminal-profile. Click on Terminal > Prefences and from there go to the Profiles tab and then to the Shell tab. Enable [x] Run command and enter export PS1='\u@\H:\w$ '.
It's just another way of doing it.
I just change the /w to /W to make just the current folder
in colored terminal
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\W\[\033[00m\]\$ 'no color terminal
PS1='${debian_chroot:+($debian_chroot)}\u@\h:\W\$ 'I use ubuntu 16.04 and change the file in ~/.bashrc
Another solution would be to make a very simple change through a framework such as oh-my-zsh, as explained in this question:
If you use the oh-my-zsh framework for instance, depending on the theme you chose to use, you'd only have to replace the %c character with %~. The reason being that %c shows the current folder, while %~ shows the full path from the root.
The file where you'd want to make the change would be something like:~/.oh-my-zsh/themes/<chosen_theme>
In my case, same as the linked question, I've selected the robbyrussell theme, so the file I had to modify was:~/.oh-my-zsh/themes/robbyrussell.zsh-theme
For safety, you can also copy the original PROMPT= line at the end of~/.zshrc before customising your theme.