Jump to content

Welcome to CodeNameJessica

✨ Welcome to CodeNameJessica! ✨

πŸ’» Where tech meets community.

Hello, Guest! πŸ‘‹
You're just a few clicks away from joining an exclusive space for tech enthusiasts, problem-solvers, and lifelong learners like you.

πŸ” Why Join?
By becoming a member of CodeNameJessica, you’ll get access to:
βœ… In-depth discussions on Linux, Security, Server Administration, Programming, and more
βœ… Exclusive resources, tools, and scripts for IT professionals
βœ… A supportive community of like-minded individuals to share ideas, solve problems, and learn together
βœ… Project showcases, guides, and tutorials from our members
βœ… Personalized profiles and direct messaging to collaborate with other techies

🌐 Sign Up Now and Unlock Full Access!
As a guest, you're seeing just a glimpse of what we offer. Don't miss out on the complete experience! Create a free account today and start exploring everything CodeNameJessica has to offer.

How to Change Your Prompt in Bash Shell in Ubuntu

(0 reviews)
I don’t like my prompt, i want to change it. it has my username and host, but the formatting is not what i want. This blog will get you started quickly on doing exactly that.

This is my current prompt below:

To change the prompt you will update .bashrc and set the PS1 environment variable to a new value.

Here is a cheatsheet of the prompt options:

You can use these placeholders for customization:

\u – Username
\h – Hostname
\w – Current working directory
\W – Basename of the current working directory
\$ – Shows $ for a normal user and # for the root user
\t – Current time (HH:MM:SS)
\d – Date (e.g., "Mon Jan 05")
\! – History number of the command
\# – Command number

I want to change my prompt to say
Here is my new prompt I am going to use:

export PS1="linuxhint@mybox \w: "

Can you guess what that does? Yes for my article writing this is exactly what i want. Here is the screenshot:

A lot of people will want the Username, Hostname, for my example i don’t! But you can use \u and \h for that. I used \w to show what directory i am in. You can also show date and time, etc.

You can also play with setting colors in the prompt with these variables:

Foreground Colors:
\e[30m – Black
\e[31m – Red
\e[32m – Green
\e[33m – Yellow
\e[34m – Blue
\e[35m – Magenta
\e[36m – Cyan
\e[37m – White

Background Colors:
\e[40m – Black
\e[41m – Red
\e[42m – Green
\e[43m – Yellow
\e[44m – Blue
\e[45m – Magenta
\e[46m – Cyan
\e[47m – White
Reset Color:
\e[0m – Reset to default

Here is my colorful version. The backslashes are primarily needed to ensure proper formatting of the prompt and avoid breaking its functionality.

export PS1="\[\e[35m\]linuxhint\[\e[0m\]@\[\e[34m\]mybox\[\e[0m\] \[\e[31m\]\w\[\e[0m\]: "


This uses Magenta, Blue and Red coloring for different parts of the prompt.

Conclusion

You can see how to customize your bash prompt with PS1 environment in Ubuntu. Hope this helps you be happy with your environment in linux.

0 Comments

Recommended Comments

There are no comments to display.

Important Information

Terms of Use Privacy Policy Guidelines We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.