Fading Coder

One Final Commit for the Last Sprint

Home > Notes > Content

Customizing Ubuntu Terminal Prompt to Display Only Current Directory

Notes May 17 3

Steps to Configure Terminal Prompt

1. Edit the Bash Configuration File

Begin by opening the .bashrc file in your user home directory. For root users, this would be located at ~/.bashrc:

nano ~/.bashrc

Locate the line that defines the PS1 variable (typically starting with PS1=). To display only the current directory name, modify it as follows:

PS1='\W\$ '

Key components explained:

  • \W: Shows only the current directory's base name (e.g., olap-engine)
  • \$: Displays $ for regular users or # for root

Alternative option using \w would show the relative path (e.g., ~/EuclidOLAP/olap-engine)

2. Save and Apply Chenges

After making the modificationns, save the file and exit the text editor. In nano, you can do this by pressing Ctrl+O followed by Enter to save, and Ctrl+X to exit.

To apply the changes immediately to your current session, execute:

source ~/.bashrc

3. Verify the New Prompt

Navigate to a directory like /root/EuclidOLAP/olap-engine. Your terminal prompt should now display:

olap-engine#

For regular users, it would appear as:

olap-engine$

4. Additional Customization Options

You can enhance your prompt with additional information using various escape sequences:

  • \u: Current username
  • \h: Hostname (first part)
  • \t: Current time in 24-hour HH:MM:SS format

Example of a customized prompt showing username and current directory:

PS1='\u@\W\$ '

This would produce a prompt like:

root@olap-engine#

By properly configuring the PS1 variable, you can create a more concise and informative terminal experience tailored to your preferences.

Related Articles

Designing Alertmanager Templates for Prometheus Notifications

How to craft Alertmanager templates to format alert messages, improving clarity and presentation. Alertmanager uses Go’s text/template engine with additional helper functions. Alerting rules referenc...

Deploying a Maven Web Application to Tomcat 9 Using the Tomcat Manager

Tomcat 9 does not provide a dedicated Maven plugin. The Tomcat Manager interface, however, is backward-compatible, so the Tomcat 7 Maven Plugin can be used to deploy to Tomcat 9. This guide shows two...

Skipping Errors in MySQL Asynchronous Replication

When a replica halts because the SQL thread encounters an error, you can resume replication by skipping the problematic event(s). Two common approaches are available. Methods to Skip Errors 1) Skip a...

Leave a Comment

Anonymous

◎Feel free to join the discussion and share your thoughts.