On my machine, due to the fact that I have things, do:
cd ~ # /work1/jleffler cd ~jleffler
The first draws attention to the value of the $HOME environment variable; I intentionally installed $HOME on the local file system instead of the file system installed on NFS. The second is read from the password file (approximately, NIS complicates the situation a bit) and discovers that the password file says that my home directory is /u/jleffler and changes to this directory.
It is an unfortunate fact that most programs behave as described above (and the POSIX specification for the shell requires this behavior). I use some software (and I donβt have much choice about use) that processes information from the password file as the current value of $ HOME, which is incorrect.
Applying this to the question, as others have pointed out, " cd ~x " goes to the user's home directory "x", and, in general, whenever the tilde extension is performed, ~x means the user's home directory 'x' (and this is an error, if user 'x' does not exist).
It could be noted that:
cd ~-
I cannot immediately find a use for ' ~+ ' unless you are doing some strange stuff with moving symbolic links in the path leading to the current directory.
You can also do:
cd -
This means ~- .
Jonathan Leffler Jun 15 '09 at 22:37 2009-06-15 22:37
source share