Customizing the Mac Terminal hostname

Posted in Mac, Bash on January 18, 2019 · 1 min read
It is fun using the Terminal on a Mac but I do not think there is a reason for the Terminal to tell me my username so n this post I let's have some fun changing the hostname.

To get started open the Terminal.app. If you do not know where the Terminal.app is, it's located in Applications > Utilities. If you plan to use or learn the Terminal I would go ahead and dock the application by dragging the application from Utilities onto your doc. With the Terminal open we can make sure we are at root by typing the command cd for Change Directory. If you would like to know more about cd or any other command for the Terminal execute man cd or you can visit Linux's man page on cd. Making sure the path is at root with cd it is time to modify the .bash_profile to tell it what we want our hostname to be and render. I am familiar with several articles that mention modifying .bashrc but when I attempted that suggestion in Mac's Yosemite operating system it did not work. Modifying the .bash_profile we run the command:

nano .bash_profile

A window should appear within the Terminal and in the head it should read File: .bash_profile. In this new window we copy and paste the line:

export PS1="whatever \w "

After adding the line we need to WriteOut and that is done with the keyboard command control+O. When the file is modified you can leave the bash file with the command control+X. Once you have left nano type the keyboard command cmd+q to exit out of the current terminal session. After closing we can double click on Terminal.app and a modified name should appear. If you want to customize beyond what I've shown here, feel free to test with a list of other commands I've compiled:

\a ## The ASCII bell character (007)
\A ## The current time in 24-hour HH:MM format
\d ## The date in "Weekday Month Day" format
\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 ## The ASCII escape character (033)
\H ## The hostname
\h ## The hostname up to the first "."
\j ## The number of jobs currently managed by the shell
\l ## The basename of the shell's terminal device name
\n ## A carriage return and line feed
\r ## A carriage return
\s ## The name of the shell
\T ## The current time in 12-hour HH:MM:SS format
\t ## The current time in HH:MM:SS format
\@ ## The current time in 12-hour a.m./p.m. format
\u ## The username of the current user
\v ## The version of bash (e.g., 2.00)
\V ## The release of bash; the version and patchlevel (e.g., 2.00.0)
\w ## The current working directory
\W ## The basename of the current working directory
\# ## The command number of the current command
\! ## The history number of the current command
\$ ## If the effective UID is 0, print a #, otherwise print a $
\nnn ## Character code in octal
[ ## Begin a sequence of non-printing characters, such as terminal control sequences
\] ## End a sequence of non-printing characters
Help the site go ad free:
Storm Trooper