Register now for better personalized quote!

HOT NEWS

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

Nov, 07, 2023 Hi-network.com
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 thepwdcommand (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 readprompt:. Obviously, you can make it read whatever you like, but for the purpose of this how-to, we'll go withprompt:.

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 calledsourcing 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 butprompt:.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 thesource 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.

Linux

The best Linux laptops for consumers and developersWant to save your aging computer? Try these 5 Linux distributionsThe best distros for beginnersHow to enable Linux on your Chromebook (and why you should)
  • The best Linux laptops for consumers and developers
  • Want to save your aging computer? Try these 5 Linux distributions
  • The best distros for beginners
  • How to enable Linux on your Chromebook (and why you should)

tag-icon Hot Tags : Tech Our process Services & Software Operating Systems LINUX

Copyright © 2014-2024 Hi-Network.com | HAILIAN TECHNOLOGY CO., LIMITED | All Rights Reserved.
Our company's operations and information are independent of the manufacturers' positions, nor a part of any listed trademarks company.