I'm only new to using SSH, but when I log in I end up in the directory ~, which in general is the same directory when FTPing in. I can still go to /, but I don't know what the ~ means. Home? Where is it in relation to /, or how could I find out?
The cd\ command takes you back to the root directory of the current drive. As shown below, if you were in the same \Windows\System32 directory and typed the cd\ command, it would take you to the C:\ directory.
The cd command, also known as chdir (change directory), is a command-line shell command used to change the current working directory in various operating systems. It can be used in shell scripts and batch files.
To navigate to your home directory, use "cd" or "cd ~" To navigate up one directory level, use "cd .." To navigate to the previous directory (or back), use "cd -" To navigate through multiple levels of directory at once, specify the full directory path that you want to go to.
You can try it out yourself by opening a Terminal window, navigating somewhere within the file system, then immediately switching directories to another location. Now just type cd – to switch back to the prior location, and cd – again to switch back to the original location.
~ is an alias to the currently logged in users home directory. To find out where that really is, type pwd
(stands for: Print Working Directory) right after logging in, which should give you the location relative to /
. It's probably something like:
/home/myusername
~ is your home directory, yes. Which is very nice since your home directory is not always where you think it should be (/home/).
Also, fun fact: You can use "cd ~myuser" to get to the home directory of the user "myuser".
As others have commented, the tilde indicates your current $HOME
directory. This may or may not be the same as the value of ~username
for your user name. On my machine, $HOME
and ~
both refer to /work1/jleffler
. However, ~jleffler
is a reference to an NFS mounted directory, /u/jleffler
, as specified in the /etc/passwd
file (or any equivalent database - the POSIX standard defines the behaviour in terms of the getpwnam()
function; see below). My profile carefully sets $HOME
. It is interesting (aka exasperating) to work out which software packages use the wrong definition of the home directory.
For most people, ~
and ~username
are the same for their user name, but that is not required. Given that you are asking the question, it is almost certainly the case that ~
and ~username
are the same.
Quote from section 2.6.1 'Tilde Expansion' of POSIX.1-2008:
A "tilde-prefix" consists of an unquoted
<tilde>
character at the beginning of a word, followed by all of the characters preceding the first unquoted<slash>
in the word, or all the characters in the word if there is no<slash>
. [...] If the login name is null (that is, the tilde-prefix contains only the tilde), the tilde-prefix is replaced by the value of the variable HOME. If HOME is unset, the results are unspecified. Otherwise, the tilde-prefix shall be replaced by a pathname of the initial working directory associated with the login name obtained using thegetpwnam()
function [...]. If the system does not recognize the login name, the results are undefined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With