Customizing Ubuntu Terminal Prompt to Display Only Current Directory
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.