Ubuntu – the difference between home$ and ~$

command linedirectorydirectory-structurelinuxUbuntu

In the below screenshot, I was not able to understand the third shortcut of Table 2-1.

It says that cd ~user_name will change the working directory to the home directory of the user_name. But, when I entered this command, I was in the same directory i.e, ~$ and not in /home$. Why?

Are they both same ?

I think the formal one is the user directory and the later one is the home directory.

Screenshot

Best Answer

Whatever you're saying about ~$, home$, and /home$ doesn't make much sense.  I guess you're talking about your command line prompt; if so, it would have been useful to show what you typed and what happened (and then explained what you expected).

But I can read minds, so I believe that I understand the issue: ~ and ~user239887 (assuming user239887 is your real user name) mean the same thing.  If you were to type

cd ~gman

that would take you to my home directory, and your shell prompt would probably look something like /home/gman$.


In the beginning, the shell prompt was always two characters — a printing character and a space.  If you were a system administrator, your prompt was ""; otherwise, it was "" or "".  And then God said, "Let there be fancy shell prompts," and, lo, there were fancy shell prompts.  Shell prompts started showing the user's name, the system name, the time, and the phase of the moon (do you think I'm kidding?), all in color.

One of the most popular customizations to the shell prompt is to include the current directory.  Your shell prompt is probably your current directory followed by "".

Another cool thing™ was that you were able to specify your own home directory by typing "~".  Because of this, when your current directory is your home directory and your shell prompt is configured to display your current directory, then the shell prompt displays "~".  But anyplace else, it shows the actual pathname (except it might show "~gman" when you are in my home directory, /home/gman).

Your home directory is probably /home/user239887.  As I said earlier, you can refer to it as ~ or ~user239887.  When you login, you are in your home directory, so your prompt is "~$ ".  If you type cd .., then you go to the /home directory, which is the parent directory of your home directory, and your prompt becomes "/home$ ".

At the risk of repeating myself, NO, /home is not your home directory.  Your home directory is probably /home/user239887.  /home is the parent directory of your home directory.

Related Question