To customize your bash prompt to show only the relative path from your home directory (i.e., a/b instead of the full path /home/USER/a/b), you can modify your PS1 environment variable in your .bashrc or .bash_profile file.
Here’s how you can do it:
Step 1: Edit your .bashrc file
Open your .bashrc file in a text editor:
Step 2: Add or modify the PS1 variable
Add or modify the following line to set your prompt to show the relative path:
\W displays the basename of the current directory (i.e., the last part of the path).
- If you want to show the full relative path (e.g.,
a/b), use \w instead of \W:
Step 3: Reload your .bashrc
After saving the file, reload it to apply the changes:
Result
Your prompt will now show the relative path from your home directory, like this:
This way, you’ll always see the path relative to your home directory, making it easier to navigate and understand your current location.