What does this symbol mean?:~
I have seen it appear when some components are going to be installed, such as:
php ~/composer.phar require cboden/ratchet
or when I make a cd in the root:
analistasistemas-VirtualBox / # cd
analistasistemas-VirtualBox ~ #
What is the name of the symbol?
~
is a symbol called a tilde that in UNIX operating systems refers to the value of the variable$HOME
, that is, the directory of the user who is logged in.This allows you to reference that directory directly, without having to write
/home/usuario/
each time.If you look at the file
/etc/passwd
, there you will see how it is defined for each of the users. Normally it is/home/nombre_de_usuario
, although for itroot
is usually/
:Well, when Bash (or another shell, since it's something defined by POSIX ) reads
~
out of quotes, it automatically expands it by the value that is found in/etc/passwd
for the user that is executing it.Therefore, in your particular case, by saying:
What will be done is:
The '~' is the absolute Path of the user you are using, ie the home folder of the user you are logged in as.
For example, I log in with the user: foo if I put
is the same as putting
when you make a 'cd' at the root it automatically adds 'cd .' if you do an 'ls -a' you will see that there is a directory (symbolic) that says './' that points to the directory where you are.
is the same as putting
And the other thing is the behavior of PS1 (prompt), if you want to know more about PS1 I leave the link here .
In Bash, the
~
or "tilde" (in English) is a special character whose most common use is to briefly indicate the special folder$HOME
that corresponds to the user's home directory. When we do something like this:cd ~
if we are the user,pedro
we will surely end up in the/home/pedro
. So common is this usage that it is lost sight of that it~
is a Bash feature to expand a folder name with multiple uses well documented in Tilde Expansion .Some uses:
~
--> the value of$HOME
~/foo
-->$HOME/foo
~fred/foo
--> The subfolderfoo
in the$HOME
user'sfred
.~+
-->$PWD
The current directoryBash has a stack where the folders where we have been browsing are registered, we can use
~
this stack to navigate (see commanddirs
):$OLDPWD
The previous directory we have been in'dirs +1'
(the next directory on the stack)'dirs -1'
(the previous directory on the stack)This is the path to your user's home folder (which is normally accessible via the $HOME environment variable).
For example, if your username is "pepe", his home folder will be in /home/pepe and typing
cd ~
will take you to that folder.As a point to keep in mind, the superuser (root) folder is not in /home/root, but directly in the root of your system, that is, in /root.
It is the path relative to the user's personal folder.
For example:
means the path of the user's home folder ~
if we have in our console something like:
if you execute
pwd
it will return the route/home/miuser
since you are placing the user's routeAn example is if you are in a folder x and you want to return to the user's folder, you can run it with the command:
this applies to all users it will look for the folder of the user you are working with with some differences in root if you don't have that folder created
It may be a little different for the root user, this will return you to the path
/root
now if you are in doubt exactly which route it is going to go to, run the following command
it will return the route that is pointing
NOTE ~ is the tilde symbol that in Linux operating systems would be an abbreviation for /home/tu-user or / (root)
If you type in the console ~ (AltGr + 4) from the root user it will show you on the screen
either
if you do it from your normal user
Therefore your line:
It would be the same as if you wrote:
and in the case of
it would be the same if you wrote
anyway write in your console ~ from any path and then give it pwd and it will show you the home of your user