As a developer or DevOp, you're likely to spend a lot of time in the Terminal, and you've probably already customized its appearance to suit you, but what about the prompt name?
The text that appears before the $ sign is the Terminal prompt name. This, by default is set to.
HOST_NAME:USER_NAME CURRENT_DIRECTORY $
This can take up a lot of valuable real-estate on each line of the Terminal, depending on what you've named your computer. To change the default prompt, you'll need to make a change to your .bash_profile
file.
Open up a new Terminal window and type the following command to ensure we're in the home directory
cd ~/
Type ls -la
to show the contents of your Home directory and check if a .bash_profile
exists.
If it does not exists, go ahead and create one with the command
touch .bash_profile
Changing your Terminal prompt
Edit '.bash_profile' with your default or favourite text editor, in my case it's Vim, with the following command
vi .bash_profile
press i
(insert) and enter the following line
export PS1="\u$ "
and save by tapping esc
key and type in :wq
,(FYI: this is specific to the Vim editor). The \u
flag sets the prompt to your username (in my case, Abayomi). Remember to keep a space after the $
symbol to make things easier to read in practice.
Quit Terminal and relaunch to see your new prompt in action.
A little extra
A little extra customization, my line looks like the following
export PS1="\u ~ >> "
and I ended uo with the following prompt
More Options for customising the prompt
The following are a few common flags you can use to customize your Terminal prompt:
\d – Current date
\t – Current time
\h – Host name
# – Command number
\u – User name
Going further
There are several options for customising your Terminal prompt including custom strings, timestamps colours and even emoji
Top comments (2)
I really like Oh My ZShell, made Terminal code color-coded by type. But I was wondering how to do this within terminal itself. thanks
I"m glad you found this useful