141

I read this up on this website and it doesn't make sense.

http://rcsg-gsir.imsb-dsgi.nrc-cnrc.gc.ca/documents/basic/node32.html

When UNIX was first written, /bin and /usr/bin physically resided on two different disks: /bin being on a smaller faster (more expensive) disk, and /usr/bin on a bigger slower disk. Now, /bin is a symbolic link to /usr/bin: they are essentially the same directory.

But when you ls the /bin folder, it has far less content than the /usr/bin folder (at least on my running system).

So can someone please explain the difference?

ctype.h
  • 556
whoami
  • 3,870
  • aren't those guys talking about a specific machine? – tshepang Jan 15 '11 at 11:57
  • 1
    @tshepang well if you keep clicking up, in the article you'll reach Basic Introduction to UNIX/linux. So I'd say no, they're not talking about a specific machine – xenoterracide Jan 15 '11 at 12:08
  • 3
    @xeno Yeah, I did, but didn't stick around long enough. In that case, that page must be taken down. So misleading. – tshepang Jan 15 '11 at 12:10
  • @whoami How did you reach that link? – tshepang Jan 15 '11 at 12:10
  • Here is the google query bin vs /usr/bin – whoami Jan 15 '11 at 12:15
  • 4
    That document can be considered 'historical reference'. If you look at the "about this document" page, you will see that it was copyrighted originally in 1993. If you look at the bibliography, it's most recent source is 1997. Most of the popular unix-like operating systems have changed substantially since then. – gabe. Jan 15 '11 at 15:02
  • 4
    Anyone interested in the historicity of this configuration should read this: http://lists.busybox.net/pipermail/busybox/2010-December/074114.html – JDS Nov 30 '16 at 19:02

5 Answers5

109

What? no /bin/ is not a symlink to /usr/bin on any FHS compliant system. Note that there are still popular Unices and Linuxes that ignore this - for example, /bin and /sbin are symlinked to /usr/bin on Arch Linux (the reasoning being that you don't need /bin for rescue/single-user-mode, since you'd just boot a live CD).

/bin

contains commands that may be used by both the system administrator and by users, but which are required when no other filesystems are mounted (e.g. in single user mode). It may also contain commands which are used indirectly by scripts

/usr/bin/

This is the primary directory of executable commands on the system.

essentially, /bin contains executables which are required by the system for emergency repairs, booting, and single user mode. /usr/bin contains any binaries that aren't required.

I will note, that they can be on separate disks/partitions, /bin must be on the same disk as /. /usr/bin can be on another disk - although note that this configuration has been kind of broken for a while (this is why e.g. systemd warns about this configuration on boot).

For full correctness, some unices may ignore FHS, as I believe it is only a Linux Standard, I'm not aware that it has yet been included in SUS, Posix or any other UNIX standard, though it should be IMHO. It is a part of the LSB standard though.

xenoterracide
  • 59,188
  • 74
  • 187
  • 252
  • So does it mean that I can share /usr/bin between two distros? like ubuntu 10.04 and 10.10? – balki Jan 15 '11 at 12:48
  • 5
    @balki no, they still have to be linked correctly, which means they'd have to be using the right version of the libs they are built against. – xenoterracide Jan 15 '11 at 13:07
  • 6
    /bin is a link to /usr/bin on some unices, such as (some releases of?) Solaris. – Gilles 'SO- stop being evil' Jan 15 '11 at 16:08
  • 1
    @balki you might be able to share /usr between two very similar distro's, though I wouldn't try it unless you know what you are doing, and you are prepared for the experiment to fail in a way that makes the computer not boot, or eat your data. Also be advised that many of the big differences between 10.04 and 10.10 will be in /usr – xenoterracide Jan 20 '11 at 13:23
  • 3
    Let's also include that /usr/local/bin is where programs that are not included with your distribution but are intended for system-wide use are installed. – Donato May 02 '15 at 06:17
  • I just checked this and I can still see /usr/bin directory with rescue mode/single-user mode/runlevel 1. Do you mean there will be no such scenario where /usr/bin will be used in the case of emergency repairs? – Karthik Jan 21 '20 at 12:43
  • It looks like /bin is symlinked to /usr/bin on Ubuntu 20.04. yep – alchemy Nov 08 '21 at 03:25
90

Update: For some history and the real reason why there is /usr, read this: http://lists.busybox.net/pipermail/busybox/2010-December/074114.html. Also this.


/sbin - Binaries needed for booting, low-level system repair, or maintenance (run level 1 or S)

/bin - Binaries needed for normal/standard system functioning at any run level.

/usr/bin - Application/distribution binaries meant to be accessed by locally logged in users

/usr/sbin - Application/distribution binaries that support or configure stuff in /sbin.

/usr/share/bin - Application/distribution binaries or scripts meant to be accesed via the web, i.e. Apache web applications

*local* - Binaries not part of a distribution; locally compiled or manually installed. There's usually never a /local/bin but always a /usr/local/bin and /usr/local/share/bin.

LawrenceC
  • 10,992
  • 6
    Oh, and you can put all these on a separate disk or partition if you like, for security or whatever. The idea is that you can umount /usr and the system will have all it needs for basic functioning, but it can't run any non-system applications. – LawrenceC Jan 19 '11 at 19:16
  • 2
    I wish I would've known this years ago. Best explanation I have seen so far. I can't say I looked very hard, but glad to finally know the answer. – David Sep 27 '13 at 07:20
  • 2
    this is a great answer. i'd donate you 10 of my own points if i could – amphibient Oct 24 '13 at 15:16
  • @ultrasawblade is /usr/bin automatically unmounted when there are no users logged in? For example, when LINUX boots and presents the login authentication, is /usr/bin mounted or no? –  Jan 13 '15 at 14:21
  • 1
    No, it's mounted at boot and stays mounted unless you unmount it, unless your system is configured unusually. – LawrenceC Jan 13 '15 at 16:12
  • @ultrasawblade I'm trying to come up with a solution to the problem described here and here. Basically, from what I understand, if the shell path is incorrect, instead of dropping to a default BASH shell, login will just fail and present "Invalid login" as the error. –  Jan 13 '15 at 20:30
  • Makes sense because /bin/false is used to prevent an account from obtaining a shell on login. You need to change /etc/passwd from a different account or a rescue boot. – LawrenceC May 31 '15 at 23:08
  • I'm using a Dockerfile which creates a binary (the some one AFAICT) in both /usr/bin and /bin. Seems unnecessary; is there any reason why it would do that? – stevec Nov 22 '22 at 14:27
23

Some kind of "update" on this issue:

Recently some Linux distributions are merging /bin into /usr/bin and relatedly /lib into /usr/lib. Sometimes also (/usr)/sbin to /usr/bin (Arch Linux). So /usr is expected to be available at the same time as /.

The distinction between the two hierarchies is taken to be unnecessary complexity now. The idea was once having only /bin available at boot, but having an initial ramdisk makes this obsolete.

I know of Fedora Linux (2011) and Arch Linux (2012) going this way and Solaris is doing this for a long time (> 15 years).

JonnyJD
  • 505
8

On Linux /bin and /usr/bin are still separate because it is common to have /usr on a separate partition (although this configuration breaks in subtle ways, sometimes). In /bin is all the commands that you will need if you only have / mounted.

On Solaris and Arch Linux (and probably others) /bin is a symlink to /usr/bin. Arch also has /sbin and /usr/sbin symlinked to /usr/bin.

Of particular note, the statement that /bin is for "system administrator" commands and /usr/bin is for user commands is not true (unless you think that bash and ls are for admins only, in which case you have a lot to learn). Administrator commands are in /sbin and /usr/sbin.

strugee
  • 14,951
bahamat
  • 39,666
  • 4
  • 75
  • 104
5

There are many UNIX-based systems. Linux, AIX, Solaris, BSD, etc. The original quote gives historical context that applies to all flavors. If you look on any one specific system, you will see different results. The last sentence of the original quote is specific to only some versions and distributions.