What is the absolute path of
cd ~ on Ubuntu?
Trying to find out where this
dir is located?
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.Sign up to join this community
cd ~ takes you to your home directory. By default, the home directory is determined by the information stored in the “passwd” database (typically
/etc/passwd on basic desktop systems, but central databases are often used in enterprise setups). However in a shell,
cd ~ (and
cd with no argument) looks at the value of the
HOME variable, so a user’s home directory can be overridden (as far as the shell is concerned) by changing that variable. The
HOME variable is initialised to point to the user’s home directory. If
HOME is unset,
cd ~ will revert to the default home directory (and
cd will fail, at least in bash).
The canonical way to determine what a given user’s home directory is, before login, is to use
getent passwd user
user’s entry in the database, and the home directory is the sixth field:
getent passwd user | cut -d: -f6
HOME environment variable will tell you what the home directory is set to, for whichever user is logged in. I.e.:
However, if the
HOME variable is not set (from
If 'HOME' is unset, the home directory of the user executing the shell is substituted instead.
You can find more information about Tilde Expansion in the
info bash manual.
In quite all shells (e.g.
~ is a shortcut for the current user home directory.
Many shells use
HOME environment variable to "cache" the position of the home directory. The initial value of
HOME is read from
As @Time4Tea stated, the best way to check the current position of
~ is to print the
HOME variable. E.g.
Remember that the value of this variable is user dependant and that the user can change it if he needs.
Last but not least, shells usually support also the
~username shortcuts. E.g.
~andcoz is my (andcoz) home and not the current user's one.