Ubuntu – Difference between $HOME and ~

home-directory

$HOME and ~ usually refer to the same thing. That is, they are the path to the "user's home" directory which is of the general form "/home/userName".

When, if ever, do these not refer to the same directory?

Best Answer

  • Both $HOME and ~ point to the same folder, the current user's home folder, but both are very different things.

    • $HOME is an environment variable, that is set to contain the home folder of the current user.
    • ~ is a shell expansion symbol, i.e., one of the symbols that is processed before the actual command is performed. ~ alone expands to the value of $HOME. ~nemo expands to the home directory of user nemo. A shell expansion symbol is a character (or pair of characters) that is processed/interpreted by the shell to build the actual command. Another example of a shell expansion symbol is *, which is used to expand file names.
  • Related Question