2.9.4. The HOME Directory

  • Directory where user is placed on login.

  • Determined by sixth field in /etc/passwd (getent passwd):

    romeo:x:500:100:romeo vincent:/home/romeo:/bin/bash
    
  • Can also be referred to by the shell variable $HOME (e.g. cat $HOME/foo).

  • Also, tilde expansion in most shells: ~ (e.g. cat ~/foo).

  • cd command used without arguments returns the user to their home directory.

  • User can create and remove files in their home directory but not in other directories.

Note

The HOME directory is changed by modifying the entry in /etc/passwd. Changing HOME does not change the home directory; rather HOME is set from the entry in /etc/passwd when a user logs in.

The ~ can be used to refer to any user’s home directory except that the form is a little different when referring to self. A / after the ~ makes all the difference:

cat ~romeo/foo Displays foo in romeo’s home directory

cat ~/foo Displays foo in my home directory

The advantage of using the ~ is that you do not need to know the pathname of the home directory to access a file in that directory structure. This facility is not available in the Bourne shell.