4

I've got a question about the prompt in Mac's Terminal. I opened Terminal and was installing GIT. I don't know anything about Unix or how to use Terminal, so please forgive my ignorance. (I know that Terminal is very powerful, though. And it's easy to screw things up!)

The prompt reads as follows:

Macintosh-2:~ myname$

What does the Macintosh-2 mean? I've never seen this in front of a Terminal prompt.

Do you think that my mac is okay? What happened to the standard prompt?

1
  • There's nothing wrong with your Mac. The "background" story I removed (edits under review) because they don't apply here. The prompt is the standard OS X prompt. See Matteo's answer for more information.
    – user10355
    Sep 22, 2011 at 7:37

1 Answer 1

6

It's your computer hostname. You can see and edit the value in "System Preferences -> Sharing -> Computer Name".

The prompt of the default shell (bash) can be changed by overriding the PS1 environment value.

# will show >
export PS1='>'

# will show the hostname followed by a space and >
export PS1='\s >'

These values are entered in a file called .bash_profile located in the root of your home directory (e.g., /Users/yourname/ or ~/). The period before the file name effectively hides it. You can read more about unix hidden files here.

You can see the complete list of special characters (e.g., \s) in the manual page of bash (your default shell).

Type man bash in the terminal and scroll down to the PROMPTING section. And if you'd like to unlock their potential, head on over to Prompt Magic and play around.

6
  • 1
    Excellent answer Matteo! I added an edit on where they can enter those values.
    – user10355
    Sep 22, 2011 at 6:17
  • @Matteo, thank you for the excellent answer. Have you ever heard of Mac OSX changing a machine's hostname for some reason? Or a virus/malware doing so? Is it something to worry about or am I over-thinking this? Thank you!
    – Laxmidi
    Sep 22, 2011 at 15:00
  • @Laxmidi: it depends, hostname can be automatically changed depending on your network location. I also some System updates add a "-2" to my default host name and never understood why.
    – Matteo
    Sep 22, 2011 at 15:03
  • @Matteo, Cool. If its happened to others, then it probably isn't something to worry about. Thanks so much.
    – Laxmidi
    Sep 22, 2011 at 15:31
  • It's recommended that you place most customizations in ~/.bashrc and have ~/.bash_profile run ~/.bashrc, so that your customizations apply to both login and non-login shells alike.
    – Chris Page
    Sep 26, 2011 at 13:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .