X
Tech
Why you can trust ZDNET : ZDNET independently tests and researches products to bring you our best recommendations and advice. When you buy through our links, we may earn a commission. Our process

'ZDNET Recommends': What exactly does it mean?

ZDNET's recommendations are based on many hours of testing, research, and comparison shopping. We gather data from the best available sources, including vendor and retailer listings as well as other relevant and independent reviews sites. And we pore over customer reviews to find out what matters to real people who already own and use the products and services we’re assessing.

When you click through from our site to a retailer and buy a product or service, we may earn affiliate commissions. This helps support our work, but does not affect what we cover or how, and it does not affect the price you pay. Neither ZDNET nor the author are compensated for these independent reviews. Indeed, we follow strict guidelines that ensure our editorial content is never influenced by advertisers.

ZDNET's editorial team writes on behalf of you, our reader. Our goal is to deliver the most accurate information and the most knowledgeable advice possible in order to help you make smarter buying decisions on tech gear and a wide array of products and services. Our editors thoroughly review and fact-check every article to ensure that our content meets the highest standards. If we have made an error or published misleading information, we will correct or clarify the article. If you see inaccuracies in our content, please report the mistake via this form.

Close

How to customize the Linux bash prompt (and why you should)

If you'd like to add a bit more personalization to your Linux command line efforts, there's a simple way to do so.
Written by Jack Wallen, Contributing Writer
Group of penguins among one that looks different
Art Wolfe/Getty Images

Linux is the most flexible operating system on the market. With many Linux distributions, the sky's the limit to what you can customize. You can tweak the look and feel of your desktop -- or change the desktop altogether -- to make it a very personal and unique experience.

Also: How to choose the right Linux desktop distribution for you

One change you might not know about is for the bash prompt. If you're unfamiliar, the bash prompt is the prompt used for running commands. You open a terminal window and you'll most likely see a prompt that looks like this:

jack@HIVE:~$

That's what my default prompt is on my Ubuntu Budgie desktop. Essentially that prompt tells me the following:

  • jack - my username
  • HIVE - the hostname of my machine
  • ~ - the current working directory (in this case, ~ equals home)

You may or may not need all of that information. For instance, when you include the current working directory in the prompt, you can wind up with a prompt so long that your commands have to wrap around in the terminal window. To me, that can get rather annoying, especially when you can simply run the pwd command (which prints out your current working directory).

Because I tend to lean toward the minimalistic, I prefer a fairly bare bash prompt. I don't want too much information cluttering up my workspace, I don't need to know who I am, and I don't need to be reminded of my computer's hostname.

Also: The best Linux laptops

Even better, I might want to ensure my bash prompt is dramatically different than that of a remote machine I might be working on, so there's no mistaking the two. To that end, I like to customize my bash prompt to include very little information. I have, on occasion, configured my bash prompt to be nothing more than a : and a space. It's effective and it's uncomplicated.

Let me show you how to customize your bash prompt.

How to configure the Linux bash prompt

What you'll need: The only thing you'll need is a running instance of Linux that uses bash as the shell. If you're using any one of the mainstream Linux distributions (such as Ubuntu, Linux Mint, and Fedora), bash is the default shell, so you're good to go.

Also: 8 things you can do with Linux that you can't do with MacOS or Windows

Do note that the customization of the bash prompt can get very complicated. Don't worry, we're going to keep it simple for now. I'll demonstrate in a later piece how to add more challenging customizations to the prompt. For now, we're going for simplicity, so you can learn how the basic customization works.

1. Open the terminal window

The first thing you'll need to do is open your terminal application from the desktop menu. Once that is opened, you should see the default bash prompt.

2. Open the .bashrc file for editing

Next, open the .bashrc file (a specific file that sets a number of configurations for a user when they log in) for editing with the command:

nano .bashrc

3. Configure the prompt

Let's say you want your bash prompt to simply read prompt:. Obviously, you can make it read whatever you like, but for the purpose of this how-to, we'll go with prompt:.

Scroll to the bottom of the .bashrc file. At the bottom of the file, add the following line:

PS1="prompt: "

NOTE: PS1 is the primary prompt string and everything in quotes is what will be printed out in the prompt.

4. Save and source .bashrc

Save and close the .bashrc file with the Ctrl+X keyboard shortcut. You'll then want to do what's called sourcing the file, so the changes take effect without having to log out and log back in. This is also a very good idea because if you've made a mistake, you'll get a chance to fix it. 

To source the .bashrc file, issue the command:

source .bashrc

You should immediately see the changes take effect, and your bash prompt will display nothing but prompt:. You can then start working without having to deal with the added information. If you don't like how this looks, you can go back and change it or delete the configuration line in .bashrc and re-run the source command.

Also: The most important reason you should be using Linux at home

And that's all there is to customize your Linux bash prompt. As I mentioned earlier, we'll revisit this topic next time around and add more information to the prompt and even a splash of color.

Editorial standards