What is the difference between /bin and ~/bin?
8,322
Solution 1
/bin
always refers to the "bin" off of the root directory "/"
In Bash,
~
refers to the users home directory.
thus ~/bin
refers to bin off of the user's home directory.
If the user's home is /users/cazs
, then ~/bin
will be /users/cazs/bin
~
seems to work in the sh
shell and its myriad of derivations, including bash
, which is what you asked about.
Solution 2
~/bin
refers to the bin
directory in the current user's home directory.
It is equivalent to $HOME/bin
.
If the current user's home directory is /home/jack
,
then ~/bin
refers to /home/jack/bin
.
/bin
is an absolute path, its meaning is unambiguous.
Related videos on Youtube
Author by
Cazs
Updated on September 18, 2022Comments
-
Cazs over 1 year
I am trying to understand exporting paths in Bash, and someone had told me that
/bin
is not the same as~/bin
. What is the difference between the two?-
jasonwryan over 7 yearsOne is a user directory, the other a system one...
-
Hack Saw over 7 yearsAlso look at man bash, then search for TILDE EXPANSION.
-
-
Hack Saw over 7 yearsIt's important to note that this is a shell feature, and not always available.
-
Hack Saw over 7 yearsAlso, ~bob/bin would refer to something like /users/bob/bin.
-
MikeP over 7 years@HackSaw, which shell doesn't support ~?
-
Hack Saw over 7 yearsMost shells that I have used support it. Python doesn't, out of the box. You have to import os.path, and perform an explicit expansion. In general programming languages don't support it, save in libraries.
-
MikeP over 7 years@HackSaw, thanks. I was interpreting that some shells don't support it. It is good to note that it is a feature of command line interface (shell), like sh, bash, zsh, csh, tcsh, etc.