What are the meanings of /usr/sbin, /usr/local/sbin and /usr/local/bin?

1. Directory structure

This should be covered in the Filesystem Hierarchy Standard (2.3 PDF)

/bin/       Essential command binaries that need to be available in single user mode;
            for all users, e.g., cat, ls, cp

/sbin/      Essential system binaries, e.g., init, ip, mount.

/usr/bin/   Non-essential command binaries (not needed in single user mode); 
            for all users

/usr/sbin/  Non-essential system binaries, e.g. daemons for various network-services.

/usr/local/ Tertiary hierarchy for local data, specific to this host. 
            Typically has further subdirectories, e.g., bin/, lib/, share/

2. Installation

I use a package manager wherever possible (e.g. yum or apt-get). This is possible for a very large number of applications, in a few cases you may have to add a repository. My second choice would be lower level packages such as RPMs and compiling from source would be my last resort (but some people prefer this)

Some package managers can install from RPMs (e.g. yum install oddity.rpm)

If you are compiling from source, its probably not a huge step to create your own package so that the system installer knows what you've done.

Then your problem reduces to e.g. yum remove packagename

The alternative is to keep good documentation about all sysadmin activities undertaken (I keep a journal in a text file anyway)


Stuff in all the */sbin directories tend to be only useful for system administrators. You can keep them out of your PATH if you're a normal user.

The different directories don't make much sense if you have a single unix machine on a single disk, but make more sense if you have a big system and different partitions. Remember that a lot of these habits were made in the 80's and 90's when systems were a bit different.

/sbin tends to be very small. These are utilities that you need when you're really hosed. You'd put this on a minimal root partition with /root and /lib. Things in /sbin used to be all statically linked, since if your /usr partition is hosed, any dynamically linked apps are useless. fsck is here and statically linked. If you have a dependency on /usr, obviously you can't fsck /usr/. Of course, if root partition is hosed, you're very screwed. This is why this is such a small partition - lower the odds of a bad disk block by using very few blocks here.

/usr/sbin binaries are general sysadmin tools where you can at least get to single user mode and mount all your volumes. They are allowed to be dynamically linked.

The separate partitions for /sbin (well, /sbin on / partition) and /usr also make more sense when you remember that backup was very expensive in both time and for tape. If they were on separate partitions, you could schedule them differently.

/usr/local can be a network filesystem. So locally written sysadmin tools that can be shared across many machines sometimes go into /usr/local/sbin. Obviously no network fixing utils can go there.

Again, a lot of things made more sense on big machines in a networked environment on managed machines with multiple volumes, less so with one Linux machine on a single root partition.


You really should have your second question be a separate question here on Superuser. It's unrelated to the first.

Yes, having files all over the place sucks. That's why there are many packaging solutions. RedHat created RPM which is used everywhere. Solaris had their package format. HP/UX had theirs, and there's apt and many other package formats. Keep things in the right places (/usr/bin, /usr/lib) as appropriate, but allow easy addition and removal.

For source, there used to be tools that would let you configure and install in a subdir of /usr/local and it would handle symlinks to /usr/local/bin for you. Since the wide proliferation of package tools, this is less necessary, and I forgot their names.

Some people like to install in /opt/packagename and keep everything together there. The good: everything is in one directory and an uninstall is rm -rf /opt/packagename. The downsides to this are having to add /opt/packagename/bin to everyone's PATH, and the fact that people usually don't put /opt on a separate partition, and you fill up the root partition.

Tags:

Linux