Tilde(~) and Slash(/) character in Linux are meta character. Within the confines of a terminal’s shell, these have special meaning.
Tilde
Tilde(~) is used to denote a user’s home directory. It contains the path to the current user home directory (it gets expanded to the $HOME env variable).
echo ~
Above command will print user home directory path.
Tilde expansion is more than home directory lookup. Adding a account’s username takes you to that account’s home directory, assuming you have permissions to view it. For example, the command cd ~bob
takes you to the home of the account named bob. Here’s a summary:
~ | $HOME |
~bob | bob home dir |
~+ | $PWD (Current working directory) |
~- | $OLDPWD (Previous directory) |
~1 | ‘dirs +1’ |
~2 | ‘dirs +2’ |
~-1 | ‘dirs -1’ |
dirs
and ~1
, ~-1
, etc., are used in conjunction with pushd
and popd
.
Slash
Slash character(/) is used by Linux as path separator. It is also used for to represent the root directory.
cd /
Above command will bring you to the root directory (topmost directory of your filesystem). The character / can never be part of a filename as it is the path separator.