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?
相关问题
- How to get the return code of a shell script in lu
- Is shmid returned by shmget() unique across proces
- how to get running process information in java?
- Invoking Mirth Connect CLI with Powershell script
- Error building gcc 4.8.3 from source: libstdc++.so
~ 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:~ is your home directory. To see the path type:
in the terminal
Different shells may or may not handle this differently, but Johnathan got the closest without coming out and saying it. The shell expands "~" to whatever's stored in the $HOME environment variable. The shell expands ~username to whatever's listed in the shell field of /etc/passwd for the given username. If you don't override it, the shell (or ssh, depending on the implementation) will set $HOME to be the home field from /etc/passwd, so they're both the same (assuming you're "username") until you change one.
As to why you see a ~ in ssh...
The prompt says "~" is your current directory most likely because you're using Bash as your shell, and the value of $PS1 (the prompt string you see - it's set in /etc/profile or /etc/profile.d/*, more than likely) contains a \w or a \W somewhere. The \w string in the prompt shows the current directory, and collapses to a "~" when you're in the directory specified by $HOME. Here's a little demo starting in my homedir - note how the "\w" gets replaced with either the current directory or with a ~, based on what the value of HOME is set to. Also note that the trailing slash doesn't work - HOME can't end with a slash for this to work. :)
Home directory need not necessarily be under /home as kigurai has pointed out.
You can try realpath
~ expands to your home directory, as has been pointed out, but I think it's worth noting that isn't a feature of ssh itself.
ssh (among many other wonderful features!) lets you establish a remote shell, and this shell can provided by many different pieces of software.
On a *nix system, your account will be associated with a particular shell, GNU bash is a popular choice. And it so happens than in bash, and most other POSIX compliant shells, the tilde character expands as a shortcut to your home directory.