How to change command prompt in FreeBSD

By default FreeBSD does not show anything in command prompt such as path, username, hostname except $. For many this can be quite annoying. As an example user does not know the current path and to get that must run pwd which is a redundant step.
To have a more user friendly prompt, just small changes should be applied to .shrc file, if the system shell is Bourne Again Shell. The file is located in home directory of each user.
Firstly, open the file and add below line before #case `id -u` in .

Keep mind of quote, back quote and double quote order. Otherwise, the prompt will not show properly.
Secondly, uncomment the following codes.

Lastly, quit from shell and login again, the prompt should be appeared like User@Hostname:path.
Usually hostname does not show in the prompt because it has not set. To set the hostname just add a line with root permission at the bottom of the /etc/rc.conf file like this.

hostname="new.host.name"

The changes in other shells such as Cshell and Zshell are quite different and shall not be covered in this post.

Leave a Reply