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.

Share:
8,322

Related videos on Youtube

Cazs
Author by

Cazs

Updated on September 18, 2022

Comments

  • Cazs
    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
      jasonwryan over 7 years
      One is a user directory, the other a system one...
    • Hack Saw
      Hack Saw over 7 years
      Also look at man bash, then search for TILDE EXPANSION.
  • Hack Saw
    Hack Saw over 7 years
    It's important to note that this is a shell feature, and not always available.
  • Hack Saw
    Hack Saw over 7 years
    Also, ~bob/bin would refer to something like /users/bob/bin.
  • MikeP
    MikeP over 7 years
    @HackSaw, which shell doesn't support ~?
  • Hack Saw
    Hack Saw over 7 years
    Most 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
    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.