Terminal prompt: how to change the displayed name of the home folder on Gnome Terminal

Asked by gabriell nascimento on 2011-11-01

The Summary is not so clear, but my doubt is pretty simple: My Gnome Terminal is showing "user@hostname: /home/user/$ " instead of "user@hostname: ~/$ ".
I just want to know how I can change it back.

Até mais.

Question information

English Edit question
Ubuntu bash Edit question
No assignee Edit question
Solved by:
Eliah Kagan
Last query:
Last reply:
delance (olivier-delance) said : #1

You must set in .bashrc the value of PS1 variable to change such prompt.
But I presume you can't replace full pathname by this shortcut.

if you run:


Does it change?


I have a desktop running Oneiric and there I don't have that problem, but the PS1 variable has the same value in both desktop (with no problems) and my notebook (with the problem I said).
I'm pretty sure I've changed a file and got the problem, but I can't remember which file was that. :-|


No, it doesn't. Doesn't matter the cd command I do, it keeps the same thing...

user@hostname:/home/user/$ and user@hostname:~/$ are both very strange prompts. Are you sure it's not currently user@hostname:/home/user$ and user@hostname:~$ ?


You're right. I put an extra "/". (Oops)

On the affected computer (the one that won't display ~), what is the output of:

echo ~

Also, what is the output of:

echo $HOME

Also, what is the output of:

echo $USER

Also, what is the output of:

echo ~$USER

If possible, it would be best for you to select the entire block of text in which you run these commands and see their output, starting with the beginning of the line on which you enter the first command, and including all the prompts. This will reveal your actual hostname and username, but it would be preferable for you to do so if you do not consider it unacceptable information disclosure, since maybe there is something about at least your username that is triggering this condition (even if it is the same username as on your other computer that doesn't have the problem).


gabriellhrn@Vulcan:/home/gabriellhrn$ echo ~
gabriellhrn@Vulcan:/home/gabriellhrn$ echo $HOME
gabriellhrn@Vulcan:/home/gabriellhrn$ echo $USER
gabriellhrn@Vulcan:/home/gabriellhrn$ echo ~$USER

There you are. Plus, the usernames are different on the computers.

It's strange that there are trailing slashes in the expansions of ~ and $HOME. I am guessing that this is the cause of the problem. A ~ is shown if the present working directory path contains it, but it doesn't contain the final slash. If a subdirectory (let's say it's called foo) of your home directory displays as "~/foo" when you cd to it, that would pretty well confirm this hypothesis. What happens when you cd to a subdirectory of your home directory?

Also, what's the output of this command?

grep gabriellhrn /etc/passwd

(The file /etc/passwd does not actually contain the password hashes of any user. Those are in /etc/shadow, which is readable only by root and should *not* be posted publicly, as the hashes can be cracked.)

If that shows your home directory as ending with a slash, then you can simply change your home directory path to remove the leading slash, and it should fix this problem. One way to do that is to run:

sudo usermod -d /home/gabriellhrn gabriellhrn

(Make sure to spell it correctly.)

If the above instructions enable you to solve the problem, then there's no need for you to post the output of anything. In that case, you can just mark this question as Solved.

You were right again! That solved my problem. Now I remember how I got the problem: I made a mess with my users and the /home that was on another partition.

Thank you very much.

Thanks Eliah Kagan, that solved my question.