Welcome to the Linux Foundation Forum!

Differences between /bin and /usr/bin & /sbin and /usr/sbin?

Hi.

I just want to clarify the difference between /bin and /usr/bin. /sbin and /usr/sbin.

When it comes to booting /bin is only useful for booting with single user and recovery mode? /sbin is the main utilities folder for booting Linux?

Everything in /usr/bin are NOT root programs (but can be used with root)? /bin contains root programs?

In more modern distributions /bin is symlinked to /usr/bin and sbin is symlinked to /usr/sbin.

Have I got this correct?

Comments

  • coop
    coop Posts: 915

    /sbin contains "administrative tools" (like fdisk say) and /bin contains programs (and scripts) that are used in many contexts (like ls, cp etc.) The distinction can be rather blurry.

    everything needed to boot the system is supposed to be in /bin and /sbin (other than the kernel and initramfs image)
    so that the system can start even before /usr is mounted (and thus /usr/bin, /usr/sbin) and is available. This also applies
    to /home, and /lib has all the stuff /bin and /sbin needs, /usr/lib has all the stuff /usr/bin and /usr/sbin have.

    This is all historical and in most situations no one boots this way anymore. It is rare for example that anyone has /usr or /home on an NFS partition (which has historically been common in Solaris). So there is really no need to have the separation anymore,
    and redhat-based distros were first to say forget it. But we still keep both directories available as symlinks because there is a lot of software that expects to find things in certain places -- which probably should not be but it is what it is.

    The comment about what is a root program" etc is not correct. everything in all these directories is owned by root, but is routinely accessed by non-privileged users. If the non-privileged user tries to mess with something they don't have permission to do (like use fdisk, fsck etc), they will be denied the right to do it, when they run the program, but they can still call it.

    I hope this helps

  • Hi @WarrenUK ,

    I just want to add that you always can compare files that you may find in more than one directory. For many cases, they will be symlinks. But there are other cases. For example, to know what's the 'ls' command the system is using, you do:

    $ which ls
    /usr/bin/ls

    *But there is also one under /bin:

    $ ls -l /bin/ls
    -rwxr-xr-x 1 root root 137888 Jan 14 2019 /bin/ls

    So, if you wonder if these are two binaries are the same, you can use 'diff':

    $ diff -s /usr/bin/ls /bin/ls
    Files /usr/bin/ls and /bin/ls are identical

    Regards,
    Luis.

  • coop
    coop Posts: 915

    on red hat, centos, fedora and probably some other distributions it is even simpler:

    ls -l / | grep bin
    lrwxrwxrwx 1 root root 7 Aug 12 2018 bin -> usr/bin
    lrwxrwxrwx 1 root root 8 Aug 12 2018 sbin -> usr/sbin

    the entire directory is just a symlink, so there is no point to comparing anything :wink:

  • Thanks guys.

    That cleared up some confusion I had.

    I have many more questions over the coming days to keep you all busy. They may sometimes be dumb so forgive my ignorance.

Categories

Upcoming Training